python中zipfile的使用_如何使用Python的zipfile模块在ZIP文件中的文件上设置权限(属性)?...

该链接比我在网上可以找到的任何其他信息都要多。 甚至zip源也没有任何内容。 复制相关部分以供后代使用。 该补丁并不是真的要记录这种格式,而只是说明当前文档的可悲性(不存在)。

# external_attr is 4 bytes in size. The high order two

# bytes represent UNIX permission and file type bits,

# while the low order two contain MS-DOS FAT file

# attributes, most notably bit 4 marking directories.

if node.isfile:

zipinfo.compress_type = ZIP_DEFLATED

zipinfo.external_attr = 0644 << 16L # permissions -r-wr--r--

data = node.get_content().read()

properties = node.get_properties()

if 'svn:special' in properties and \

data.startswith('link '):

data = data[5:]

zipinfo.external_attr |= 0120000 << 16L # symlink file type

zipinfo.compress_type = ZIP_STORED

if 'svn:executable' in properties:

zipinfo.external_attr |= 0755 << 16L # -rwxr-xr-x

zipfile.writestr(zipinfo, data)

elif node.isdir and path:

if not zipinfo.filename.endswith('/'):

zipinfo.filename += '/'

zipinfo.compress_type = ZIP_STORED

zipinfo.external_attr = 040755 << 16L # permissions drwxr-xr-x

zipinfo.external_attr |= 0x10 # MS-DOS directory flag

zipfile.writestr(zipinfo, '')

另外,此链接包含以下内容。这里的低位字节大概是指四个字节中最右边(最低)的字节。 所以这个是对于MS-DOS,大概可以保留为零。

外部文件属性:(4个字节)

The mapping of the external attributes is

host-system dependent (see 'version made by'). For

MS-DOS, the low order byte is the MS-DOS directory

attribute byte. If input came from standard input, this

field is set to zero.

另外,从Debian的档案中下载的InfoZIP zip程序的源文件中的unix / unix.c源文件在注释中具有以下内容。

/* lower-middle external-attribute byte (unused until now):

* high bit => (have GMT mod/acc times) >>> NO LONGER USED! <<<

* second-high bit => have Unix UID/GID info

* NOTE: The high bit was NEVER used in any official Info-ZIP release,

* but its future use should be avoided (if possible), since it

* was used as "GMT mod/acc times local extra field" flags in Zip beta

* versions 2.0j up to 2.0v, for about 1.5 years.

*/

因此,将所有这些结合在一起,至少在Unix中,实际上似乎只使用了第二个最高字节。

编辑:我在“ zip格式的外部文件属性”问题中询问了Unix.SX的Unix方面。 看来我做错了两件事。 具体来说,前两个字节都用于Unix。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值