LIBZIP 是否提供了一种检查zip_file是否是目录的方法?

Does LIBZIP provides a way to check if zip_file is a DIRECTORY?

本文关键字:是否是 file zip 方法 检查 一种 是否 LIBZIP      更新时间:2023-10-16

由于兼容性问题,我使用的是相当旧版本的libzip(0.10.1-1.2(。

通常我们会通过其统计结果检查文件类型(符号链接、目录、文件等(。类似地,在libzip上我们zip_stat,但它的结构不包含文件系统STA中ST_MOD的内容。

struct zip_stat {
    zip_uint64_t valid;         /* which fields have valid values */
    const char *name;           /* name of the file */
    zip_uint64_t index;         /* index within archive */
    zip_uint64_t size;          /* size of file (uncompressed) */
    zip_uint64_t comp_size;     /* size of file (compressed) */
    time_t mtime;           /* modification time */
    zip_uint32_t crc;           /* crc of file data */
    zip_uint16_t comp_method;       /* compression method used */
    zip_uint16_t encryption_method; /* encryption method used */
    zip_uint32_t flags;         /* reserved for future use */
};

有没有办法检查条目是否是 DIR?

是的。检查name的最终字符是否'/'。只有目录以 '/' 结尾。

来源:

  • https://libzip.org/documentation/zip_file_rename.html#ZIP_ER_INVAL
  • libzip 源代码中的许多地方都使用此规则。格雷普'/'去看他们。