是否可以在Windows上将zip文件中的文件标记为Unix可执行文件?

时间:2014-08-11 00:49:02

标签: ruby windows unix zip

这是一个奇怪的问题。我有一个构建Unity游戏的持续集成服务器(Windows 7)。我正在构建的平台之一是Linux,它类似于Windows构建过程,为该平台和数据文件夹创建可执行文件。一旦我压缩这些文件,然后在Linux上提取它,可执行文件没有标记为执行。是否有可能在Windows中将此文件设置为 - 并且仅将此文件的 - 权限设置为可执行文件(例如chmod +x filename),如果是,我该如何实现?

如果涉及脚本,我不介意它在哪种语言,但我确实偏爱Ruby,因为我正在使用它来自动压缩这些文件。这是我到目前为止所做的:

# Import modules
require 'zip'

# Define constants
PLATFORM_STRINGS = [' (Windows 32-bit)', \
                    ' (Windows 64-bit)', \
                    ' (Mac 32-bit)', \
                    ' (Mac 64-bit)', \
                    ' (Linux 32-bit)', \
                    ' (Linux 64-bit)', \
                    ' (Web)']

# Change directory
Dir.chdir(ARGV[0])

def get_application_name(directory)
    for platform in PLATFORM_STRINGS
        if directory.end_with?(platform)
            return directory.sub(platform, '')
        end
    end
end

# Find all directories in this folder
for directory in Dir['*']

    # Check if file is a directory
    if File.directory?(directory)

        # Retrieve the application name for this directory
        application_name = get_application_name(directory)
        zip_file_name = "#{directory}.zip"
        # Create a zip file
        Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile|

            # Traverse recursively through all files
            Dir[File.join(directory, '**', '**')].each do |file|

                # Replace the top-level directory name with the application's name
                zipfile.add(file.sub(directory, application_name), file)
            end
        end

        # Indicate the zip file that was created
        puts "> Created: " + zip_file_name
    end
end

1 个答案:

答案 0 :(得分:0)

使用我的 windows 命令行实用程序 zip_exec.zip 为 unix 和 mac 设置可执行标志。源也可用。