gradle解压缩后维护文件权限 [英] Maintain file permission after gradle unzip

查看:182
本文介绍了gradle解压缩后维护文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的gradle任务,该任务解压缩一个zip文件并将其复制到本地目录.问题是执行后,我所有文件的权限都更改了.

I have a simple gradle task that unzips a zip file and copies it to a local directory. The problem is, after execution, all my files have their permissions changed.

这是我的毕业任务:

task unzip(type: Copy) {
    def zipFile = file('src/dists/dist.zip')
    def outputDir = file("${buildDir}/unpacked/dist")

    from zipTree(zipFile)
    into outputDir
}

但是在执行解压缩"任务后,我所有的原始文件都具有

But after executing "unzip" task, all my files, which originally had

rwxr-xr-x

rwxr-xr-x

权限变为

rw-r--r-

rw-r--r--

为什么我的任务剥离执行所有文件中的执行权限?有没有办法告诉我的gradle任务保留文件权限?

Why is my task stripping execute permission from all my files? Is there a way to tell my gradle task to keep file permissions?

推荐答案

首先,请注意,将文件权限存储在zip文件中

First, note that storing file permissions in zip file is not trivial. It is not clear from your question if you have stored permissions in the zip file.

我不知道如何告诉Gradle 维护权限,但是,这可能是可以接受的(?):Copy任务上的fileMode参数(此处的文档)可用于分配权限.

I don't know how to tell Gradle to maintain the permissions, but, this might be acceptable (?): the fileMode parameter on the Copy task (doc here) can be used to assign permissions.

例如:

task unzip(type: Copy) {
    fileMode = 0755 
    def zipFile = file('src/dists/dist.zip')
    def outputDir = file("${buildDir}/unpacked/dist")

    from zipTree(zipFile)
    into outputDir
}

产生权限,例如:

bash$ ls -lrt build/unpacked/dist/
total 0
-rwxr-xr-x  [snip] 9 Aug 22:42 run.sh
-rwxr-xr-x  [snip] 9 Aug 22:42 example1.sh
-rwxr-xr-x  [snip] 9 Aug 22:42 foobar.txt

这篇关于gradle解压缩后维护文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆