【问题标题】:C++ Adding File Permissions to Zip FileC++ 将文件权限添加到 Zip 文件
【发布时间】:2012-10-04 15:31:25
【问题描述】:

我正在用 C++ 编写一个压缩程序。我想添加安全描述符,以便在压缩时保留我的文件权限。我正在使用 Zlib 的 Minizip 压缩文件,我知道 Minizip 没有保存文件权限的能力。我认为我可能必须手动将安全描述添加到额外字段中。

如何获取文件的安全权限?

如何格式化 zip 文件的安全描述符?

【问题讨论】:

    标签: c++ zip file-permissions zlib


    【解决方案1】:

    看看Info-ZIP's zip and unzip 实用程序。它们为各种操作系统提供比基本 minizip 功能更广泛的支持。

    自己动手,可以参考Info-ZIP appnote。 Windows 额外字段在那里定义,复制到这里:

             -PKWARE Win95/WinNT Extra Field (0x000a):
              =======================================
    
              The following description covers PKWARE's "NTFS" attributes
              "extra" block, introduced with the release of PKZIP 2.50 for
              Windows. (Last Revision 20001118)
    
              (Note: At this time the Mtime, Atime and Ctime values may
              be used on any WIN32 system.)
             [Info-ZIP note: In the current implementations, this field has
              a fixed total data size of 32 bytes and is only stored as local
              extra field.]
    
              Value         Size        Description
              -----         ----        -----------
      (NTFS)  0x000a        Short       Tag for this "extra" block type
              TSize         Short       Total Data Size for this block
              Reserved      Long        for future use
              Tag1          Short       NTFS attribute tag value #1
              Size1         Short       Size of attribute #1, in bytes
              (var.)        SubSize1    Attribute #1 data
              .
              .
              .
              TagN          Short       NTFS attribute tag value #N
              SizeN         Short       Size of attribute #N, in bytes
              (var.)        SubSizeN    Attribute #N data
    
              For NTFS, values for Tag1 through TagN are as follows:
              (currently only one set of attributes is defined for NTFS)
    
              Tag        Size       Description
              -----      ----       -----------
              0x0001     2 bytes    Tag for attribute #1
              Size1      2 bytes    Size of attribute #1, in bytes (24)
              Mtime      8 bytes    64-bit NTFS file last modification time
              Atime      8 bytes    64-bit NTFS file last access time
              Ctime      8 bytes    64-bit NTFS file creation time
    
              The total length for this block is 28 bytes, resulting in a
              fixed size value of 32 for the TSize field of the NTFS block.
    
              The NTFS filetimes are 64-bit unsigned integers, stored in Intel
              (least significant byte first) byte order. They determine the
              number of 1.0E-07 seconds (1/10th microseconds!) past WinNT "epoch",
              which is "01-Jan-1601 00:00:00 UTC".
    

    【讨论】:

    • 谢谢,我们实际上将代码从以前使用 Info-Zip 更改为现在使用 Minizip,因为我们需要 zip64 支持。但是,如果您能给我一些关于如何手动获取权限的想法,我认为我可以自己将它们添加到额外的数据字段中。
    • 或者,如果您可以为 Info-Zip 添加 zip64 支持,那就太好了! :)
    • 您试图在哪种系统上保留权限属性?
    • 感谢您的所有帮助,我非常感谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多