解压缩时使用ant保留文件权限和压缩文件

phe*_*cks 10 ant zip build-process unzip

我正在编写一个ant build.xml文件,它执行以下操作:

  • 采用压缩文件夹(.zip)
  • 解压缩它
  • 添加了许多文件
  • 压缩生成的文件

build.xml中的代码摘录:

<!-- Unzip SDK to a temporary directory -->
<unzip src="${zipFile}" dest="tmp"/>

<!-- pull in the files from another directory -->
<copy todir="tmp/someDirectory" >
  <fileset dir="${addedFiles}" />
</copy>

<!-- Zip up modified SDK -->
<zip destfile="${destDir}" basedir="tmp"/>
Run Code Online (Sandbox Code Playgroud)

除了在运行ant构建之前为压缩文件设置的权限在ant构建创建的zip文件中丢失之外,这一切都很有效.例如,以前可执行的文件不再是.

所以我的问题是:是否可以使用ant将文件添加到zip存档而不破坏已存在文件的权限?

我正在使用Ant 1.7.1

Jak*_*e W 9

使用Ant解压缩目标时遇到了同样的问题:

<unzip src="${project.build.directory}/${project.build.finalName}.zip" dest="${user.home}/apps" overwrite="true" />
Run Code Online (Sandbox Code Playgroud)

使用上面的解压缩目标时,zip文件中的shell脚本的权限丢失了.

经过一些调查,我使用了跟随'exec'的ant目标和解压缩命令行参数,它工作正常.

<!-- Use command line unzip to keep file permissions -->
<exec executable="unzip" spawn="true">
    <arg line="-o ${project.build.directory}/${project.build.finalName}.zip -d ${user.home}/apps" />
</exec>
Run Code Online (Sandbox Code Playgroud)

我希望在遇到这类问题时,这可以帮助别人.

谢谢,J


non*_*ont 7

您无法获取zip任务以保留文件权限,但您可以显式设置它们:

<zip destfile="installer.zip" >
<zipfileset filemode="755" dir="../" includes="artisan/install.*" />
</zip>
Run Code Online (Sandbox Code Playgroud)

(这适用于Windows和OSX)


phe*_*cks 3

事实证明,由于Java的限制,ant在解压时会破坏所有权限信息。但是,可以将文件添加到现有 zip 文件中,从而保留现有文件的权限:

<!-- Add to zip -->
<zip destfile="${existingZipFiledirectory}.zip"
   basedir="${directoryOfFilesToAdd}"
   update="true"
/>
Run Code Online (Sandbox Code Playgroud)

上面的脚本将更新使用 basedir 中的内容指定的 zip 文件,保留原始 zip 中的文件权限。