]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 196: cpio format tests should verify that nlinks in the
authorTim Kientzle <kientzle@gmail.com>
Sat, 12 Nov 2011 05:21:58 +0000 (00:21 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 12 Nov 2011 05:21:58 +0000 (00:21 -0500)
archive matches what's on disk, instead of assuming historical
Unix behavior.
Thanks to: dpmcgee

SVN-Revision: 3766

cpio/test/test.h
cpio/test/test_format_newc.c
cpio/test/test_option_c.c
libarchive/test/test.h
tar/test/test.h

index 05fa2c3810f555bfe9f416ac3b8379cb7f35cee3..9d2c7d78811fc89c69a8efe58864bde96b9b8aaa 100644 (file)
 #pragma warn -8068     /* Constant out of range in comparison. */
 #endif
 
-/* Cygwin */
-#if defined(__CYGWIN__)
-/* Cygwin-1.7.x is lazy about populating nlinks, so don't
- * expect it to be accurate. */
-# define NLINKS_INACCURATE_FOR_DIRS
-#endif
-
 /* Haiku OS and QNX */
 #if defined(__HAIKU__) || defined(__QNXNTO__)
 /* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
index e1047e5b4e93cb50342d2d9848e096b02c35984f..365859a5218ca1e4f79e4a134a17ad318627d24f 100644 (file)
@@ -68,6 +68,14 @@ from_hex(const char *p, size_t l)
        return (r);
 }
 
+static int
+nlinks(const char *p)
+{
+       struct stat st;
+       assertEqualInt(0, stat(p, &st));
+       return st.st_nlink;
+}
+
 DEFINE_TEST(test_format_newc)
 {
        FILE *list;
@@ -241,11 +249,9 @@ DEFINE_TEST(test_format_newc)
        /* Mode: sgid bit sometimes propagates from parent dirs, ignore it. */
        assertEqualInt(040775, from_hex(e + 14, 8) & ~02000);
 #endif
-       assertEqualInt(from_hex(e + 22, 8), uid); /* uid */
+       assertEqualInt(uid, from_hex(e + 22, 8)); /* uid */
        assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
-#ifndef NLINKS_INACCURATE_FOR_DIRS
-       assertEqualMem(e + 38, "00000002", 8); /* nlink */
-#endif
+       assertEqualInt(nlinks("dir"), from_hex(e + 38, 8)); /* nlinks */
        t2 = from_hex(e + 46, 8); /* mtime */
        failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
        assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
index 241bcf67bb156f6110bce67c415f013f43ba1699..f9fbc92df02ff31324df7f9773fadb5ce8d42e46 100644 (file)
@@ -51,6 +51,14 @@ from_octal(const char *p, size_t l)
        return (r);
 }
 
+static int
+nlinks(const char *p)
+{
+       struct stat st;
+       assertEqualInt(0, stat(p, &st));
+       return st.st_nlink;
+}
+
 DEFINE_TEST(test_option_c)
 {
        FILE *filelist;
@@ -185,13 +193,13 @@ DEFINE_TEST(test_option_c)
        if (memcmp(e + 18, "042775", 6) != 0)
                assertEqualMem(e + 18, "040775", 6); /* Mode */
 #endif
-       assertEqualInt(from_octal(e + 24, 6), uid); /* uid */
+       assertEqualInt(uid, from_octal(e + 24, 6)); /* uid */
        /* Gid should be same as first entry. */
        assert(is_octal(e + 30, 6)); /* gid */
        assertEqualInt(gid, from_octal(e + 30, 6));
-#ifndef NLINKS_INACCURATE_FOR_DIRS
-       assertEqualMem(e + 36, "000002", 6); /* Nlink */
-#endif
+
+       assertEqualInt(nlinks("dir"), from_octal(e + 36, 6)); /* Nlink */
+
        t = from_octal(e + 48, 11); /* mtime */
        assert(t <= now); /* File wasn't created in future. */
        assert(t >= now - 2); /* File was created w/in last 2 secs. */
index d9c6a08ec1bbc5151f452b97427a63d7d522e6e5..19aee761a0eaec21d3c03d6a7896d24e322984da 100644 (file)
 #pragma warn -8068     /* Constant out of range in comparison. */
 #endif
 
-/* Cygwin */
-#if defined(__CYGWIN__)
-/* Cygwin-1.7.x is lazy about populating nlinks, so don't
- * expect it to be accurate. */
-# define NLINKS_INACCURATE_FOR_DIRS
-#endif
-
 /* Haiku OS and QNX */
 #if defined(__HAIKU__) || defined(__QNXNTO__)
 /* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
index c4088cbbae2be704f7115b5c0a57ff8f05c89dc5..7166493a20ddaff7ad7638d0461848edd25f870e 100644 (file)
 #pragma warn -8068     /* Constant out of range in comparison. */
 #endif
 
-/* Cygwin */
-#if defined(__CYGWIN__)
-/* Cygwin-1.7.x is lazy about populating nlinks, so don't
- * expect it to be accurate. */
-# define NLINKS_INACCURATE_FOR_DIRS
-#endif
-
 /* Haiku OS and QNX */
 #if defined(__HAIKU__) || defined(__QNXNTO__)
 /* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */