开发者

Can I set the permissions of the contents of a dynamically generated zip file in Google App Engine?

开发者 https://www.devze.com 2023-01-30 23:45 出处:网络
In my app engine script (using the Python API), I\'m using this code to dynamically generate zip files and serve them back to the user. When I download and extract the generated zip file and I\'m runn

In my app engine script (using the Python API), I'm using this code to dynamically generate zip files and serve them back to the user. When I download and extract the generated zip file and I'm running OS X, the permissions of each file extracted from the archive is 0, forcing me to chmod them. I'd rather not have my users have to do the same. Is there a way t开发者_StackOverflowo fix this?


Yup, see the docs for the Python zipfile module. Specifically, the signature of the writestr method, which is:

ZipFile.writestr(zinfo_or_arcname, bytes[, compress_type])

The first argument can be the filename, or a ZipInfo object, which allows you to specify information about the file to be stored. I believe the relevant field to set to change the permissions of the file is the external_attr, but some experimentation reading existing zip files may be required to determine this.

0

精彩评论

暂无评论...
验证码 换一张
取 消