]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Don't default XAR entry atime/mtime to the current time 1070/head
authorZack Weger <ZWeger@StrozFriedberg.com>
Tue, 2 Oct 2018 22:19:27 +0000 (18:19 -0400)
committerZack Weger <ZWeger@StrozFriedberg.com>
Tue, 2 Oct 2018 22:19:27 +0000 (18:19 -0400)
libarchive/archive_read_support_format_xar.c
libarchive/test/test_read_format_xar.c

index 602fc77221444ace07bbc77e2cc517dea0afd9e3..5933fce919c05faa09e0d9cd5e12c8a7b6e5bb15 100644 (file)
@@ -167,6 +167,9 @@ struct xar_file {
 #define HAS_FFLAGS             0x01000
 #define HAS_XATTR              0x02000
 #define HAS_ACL                        0x04000
+#define HAS_CTIME              0x08000
+#define HAS_MTIME              0x10000
+#define HAS_ATIME              0x20000
 
        uint64_t                 id;
        uint64_t                 length;
@@ -695,9 +698,15 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
                 */
                file_free(file);
        }
-       archive_entry_set_atime(entry, file->atime, 0);
-       archive_entry_set_ctime(entry, file->ctime, 0);
-       archive_entry_set_mtime(entry, file->mtime, 0);
+        if (file->has & HAS_ATIME) {
+          archive_entry_set_atime(entry, file->atime, 0);
+        }
+        if (file->has & HAS_CTIME) {
+          archive_entry_set_ctime(entry, file->ctime, 0);
+        }
+        if (file->has & HAS_MTIME) {
+          archive_entry_set_mtime(entry, file->mtime, 0);
+        }
        archive_entry_set_gid(entry, file->gid);
        if (file->gname.length > 0 &&
            archive_entry_copy_gname_l(entry, file->gname.s,
@@ -1767,8 +1776,8 @@ file_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list)
        }
        file->parent = xar->file;
        file->mode = 0777 | AE_IFREG;
-       file->atime = time(NULL);
-       file->mtime = time(NULL);
+       file->atime =  0;
+       file->mtime = 0;
        xar->file = file;
        xar->xattr = NULL;
        for (attr = list->first; attr != NULL; attr = attr->next) {
@@ -2751,15 +2760,15 @@ xml_data(void *userData, const char *s, int len)
                xar->file->uid = atol10(s, len);
                break;
        case FILE_CTIME:
-               xar->file->has |= HAS_TIME;
+               xar->file->has |= HAS_TIME | HAS_CTIME;
                xar->file->ctime = parse_time(s, len);
                break;
        case FILE_MTIME:
-               xar->file->has |= HAS_TIME;
+               xar->file->has |= HAS_TIME | HAS_MTIME;
                xar->file->mtime = parse_time(s, len);
                break;
        case FILE_ATIME:
-               xar->file->has |= HAS_TIME;
+               xar->file->has |= HAS_TIME | HAS_ATIME;
                xar->file->atime = parse_time(s, len);
                break;
        case FILE_DATA_LENGTH:
index b7189eb259e6d77adfea77aa0baf2bcfb8c5f3dd..ae212de2d3c5d7497de41665e13d9a9f211d46d4 100644 (file)
@@ -614,6 +614,65 @@ static unsigned char archive11[] = {
 0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47
 };
 
+/* Verify that a file which is missing timestamp information
+has the corresponding timestamps unset.
+#How to make e.g.
+  struct archive *a = archive_write_new();
+  archive_write_set_format_xar(a);
+  archive_write_add_filter_none(a);
+  size_t used, buffsize = 1500;
+  char *buff = (char*) malloc(buffsize);
+  archive_write_open_memory(a, buff, buffsize, &used);
+
+  struct archive_entry *ae = archive_entry_new();
+  archive_entry_copy_pathname(ae, "file");
+  archive_entry_set_size(ae, 8);
+  archive_write_header(a, ae);
+  archive_entry_free(ae);
+  archive_write_data(a, "12345678", 9);
+  archive_write_free(a);
+
+  std::cout << std::string(buff, used);
+  free(buff);
+
+$./a.out > f12.xar
+Verify toc has no mtime/atime sections
+$ xar --dump-toc=- -f f12.xar
+Dump contents
+$ ./a.out | od -t x1 | sed -E -e 's/^0[0-9]+//;s/^  //;s/(  )([0-9a-f]{2})/0x\2,/g;$ D'
+*/
+
+static unsigned char archive12[] = {
+0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd1,
+0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x56,0x00,0x00,0x00,0x01,0x78,0x9c,0x55,0x90,
+0x41,0x8e,0xc2,0x30,0x0c,0x45,0xf7,0x9c,0x22,0xca,0xbe,0x38,0x2d,0x2c,0x10,0x72,
+0xdb,0xdd,0x9c,0x00,0x0e,0x50,0xb5,0x6e,0x89,0x68,0x12,0xd4,0x84,0x11,0x70,0x7a,
+0x62,0x17,0x46,0x9a,0x28,0x92,0xbf,0x5f,0xec,0xef,0xc8,0xd8,0x3e,0xdc,0xac,0x7e,
+0x69,0x89,0x36,0xf8,0x5a,0x97,0x5b,0xa3,0x15,0xf9,0x3e,0x0c,0xd6,0x4f,0xb5,0x3e,
+0x9f,0x7e,0x8a,0x83,0x6e,0x9b,0x0d,0x3e,0xba,0xa5,0xd9,0x28,0x4c,0xa1,0xcf,0x41,
+0x61,0xbf,0x50,0x97,0x72,0x47,0x91,0xac,0xa3,0xa6,0x32,0xe5,0xa1,0x28,0x4d,0x61,
+0xaa,0x53,0x65,0x8e,0xf9,0xee,0x77,0x08,0xff,0x4b,0xa4,0xe9,0x42,0xfd,0x35,0xde,
+0x9d,0x8a,0xe9,0x39,0x53,0xad,0xe3,0xa5,0x2b,0x35,0xbf,0x28,0x0c,0xe3,0x18,0x29,
+0x35,0x06,0xe1,0xa3,0x84,0x46,0xfb,0x62,0x73,0x04,0x11,0x6c,0x01,0x5f,0x0f,0xc9,
+0x46,0x3b,0x93,0xb2,0x43,0xfe,0xf6,0xc7,0xc6,0x77,0x79,0x14,0x53,0x04,0x91,0x02,
+0xd3,0xf3,0xf6,0x85,0x22,0x05,0x5a,0x1f,0x06,0xe2,0x79,0xab,0x10,0xe6,0x04,0xe5,
+0x83,0xe0,0xfe,0xe0,0xdd,0x0e,0x5c,0xc6,0x41,0xf2,0x69,0xcd,0xa7,0x35,0x47,0x60,
+0x63,0xde,0x0c,0xc8,0x6a,0x10,0x64,0x51,0x6f,0x2a,0x6b,0x63,0x9a,0x01,0x79,0x57,
+0x93,0xd4,0x55,0xd4,0x06,0x1c,0x76,0x99,0x10,0x31,0x87,0x52,0x2b,0x16,0xff,0x5b,
+0x36,0x78,0x9c,0x55,0x90,0x41,0x8e,0xc2,0x30,0x0c,0x45,0xf7,0x9c,0x22,0xca,0xbe,
+0x38,0x2d,0x2c,0x10,0x72
+};
+
+static void verify12(struct archive *a, struct archive_entry *ae)
+{
+       (void)a; /* UNUSED */
+        assertEqualInt(archive_entry_mtime_is_set(ae), 0);
+        assertEqualInt(archive_entry_atime_is_set(ae), 0);
+       assertEqualInt(archive_entry_mtime(ae), 0);
+       assertEqualInt(archive_entry_atime(ae), 0);
+}
+
+
 enum enc {
     GZIP,
     BZIP2
@@ -698,5 +757,6 @@ DEFINE_TEST(test_read_format_xar)
        verify(archive9, sizeof(archive9), verify0, NULL, GZIP);
        verify(archive10, sizeof(archive10), verify0, NULL, GZIP);
        verify(archive11, sizeof(archive11), verify0, NULL, GZIP);
+        verify(archive12, sizeof(archive12), verify12, NULL, GZIP);
 }