Skip to content

Commit

Permalink
Issue 196: cpio format tests should verify that nlinks in the
Browse files Browse the repository at this point in the history
archive matches what's on disk, instead of assuming historical
Unix behavior.
Thanks to: dpmcgee

SVN-Revision: 3766
  • Loading branch information
kientzle committed Nov 12, 2011
1 parent 1970dd5 commit 8068bcb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
7 changes: 0 additions & 7 deletions cpio/test/test.h
Expand Up @@ -101,13 +101,6 @@
#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) */
Expand Down
14 changes: 10 additions & 4 deletions cpio/test/test_format_newc.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
16 changes: 12 additions & 4 deletions cpio/test/test_option_c.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
7 changes: 0 additions & 7 deletions libarchive/test/test.h
Expand Up @@ -97,13 +97,6 @@
#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) */
Expand Down
7 changes: 0 additions & 7 deletions tar/test/test.h
Expand Up @@ -101,13 +101,6 @@
#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) */
Expand Down

0 comments on commit 8068bcb

Please sign in to comment.