From: Michihiro NAKAJIMA Date: Wed, 13 Apr 2011 10:43:55 +0000 (-0400) Subject: Consider the large i-node number for the tests using cpio newc format. X-Git-Tag: v3.0.0a~464 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a01630949de878cb081c2ab586642e83effce28e;p=thirdparty%2Flibarchive.git Consider the large i-node number for the tests using cpio newc format. Some cpio tests on Cygwin 1.7.x always failed because of the large i-node number. SVN-Revision: 3222 --- diff --git a/cpio/test/main.c b/cpio/test/main.c index c0166f692..78f11e63a 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -153,7 +153,7 @@ my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) memset(bhfi, 0, sizeof(*bhfi)); h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) return (0); r = GetFileInformationByHandle(h, bhfi); @@ -1691,6 +1691,27 @@ extract_reference_file(const char *name) fclose(in); } +int +is_LargeInode(const char *file) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + BY_HANDLE_FILE_INFORMATION bhfi; + int r; + + r = my_GetFileInformationByName(file, &bhfi); + if (r != 0) + return (0); + return (bhfi.nFileIndexHigh & 0x0000FFFFUL); +#else + struct stat st; + int64_t ino; + + if (stat(file, &st) < 0) + return (0); + ino = (int64_t)st.st_ino; + return (ino > 0xffffffff); +#endif +} /* * * TEST management diff --git a/cpio/test/test.h b/cpio/test/test.h index a552c8f5b..05fa2c381 100644 --- a/cpio/test/test.h +++ b/cpio/test/test.h @@ -273,6 +273,9 @@ int canGzip(void); /* Return true if this platform can run the "gunzip" program. */ int canGunzip(void); +/* Return true if the file has large i-node number(>0xffffffff). */ +int is_LargeInode(const char *); + /* Suck file into string allocated via malloc(). Call free() when done. */ /* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ char *slurpfile(size_t *, const char *fmt, ...); diff --git a/cpio/test/test_basic.c b/cpio/test/test_basic.c index 1a3810461..c40813e9a 100644 --- a/cpio/test/test_basic.c +++ b/cpio/test/test_basic.c @@ -64,7 +64,7 @@ static void basic_cpio(const char *target, const char *pack_options, const char *unpack_options, - const char *se) + const char *se, const char *se2) { int r; @@ -93,7 +93,7 @@ basic_cpio(const char *target, /* Verify stderr. */ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); - assertTextFileContents(se, "unpack.err"); + assertTextFileContents(se2, "unpack.err"); verify_files(pack_options); @@ -131,6 +131,7 @@ DEFINE_TEST(test_basic) { FILE *filelist; const char *msg; + char result[1024]; assertUmask(0); @@ -138,28 +139,56 @@ DEFINE_TEST(test_basic) * Create an assortment of files on disk. */ filelist = fopen("filelist", "w"); + memset(result, 0, sizeof(result)); /* File with 10 bytes content. */ assertMakeFile("file", 0644, "1234567890"); fprintf(filelist, "file\n"); + if (is_LargeInode("file")) + strncat(result, + "bsdcpio: file: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result)); /* hardlink to above file. */ assertMakeHardlink("linkfile", "file"); fprintf(filelist, "linkfile\n"); + if (is_LargeInode("linkfile")) + strncat(result, + "bsdcpio: linkfile: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result)); /* Symlink to above file. */ if (canSymlink()) { assertMakeSymlink("symlink", "file"); fprintf(filelist, "symlink\n"); + if (is_LargeInode("symlink")) + strncat(result, + "bsdcpio: symlink: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result)); } /* Another file with different permissions. */ assertMakeFile("file2", 0777, "1234567890"); fprintf(filelist, "file2\n"); + if (is_LargeInode("file2")) + strncat(result, + "bsdcpio: file2: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result)); /* Directory. */ assertMakeDir("dir", 0775); fprintf(filelist, "dir\n"); + if (is_LargeInode("dir")) + strncat(result, + "bsdcpio: dir: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result)); + strncat(result, "2 blocks\n", sizeof(result) - strlen(result)); + /* All done. */ fclose(filelist); @@ -167,12 +196,12 @@ DEFINE_TEST(test_basic) /* Archive/dearchive with a variety of options. */ msg = canSymlink() ? "2 blocks\n" : "1 block\n"; - basic_cpio("copy", "", "", msg); - basic_cpio("copy_odc", "--format=odc", "", msg); - basic_cpio("copy_newc", "-H newc", "", "2 blocks\n"); - basic_cpio("copy_cpio", "-H odc", "", msg); + basic_cpio("copy", "", "", msg, msg); + basic_cpio("copy_odc", "--format=odc", "", msg, msg); + basic_cpio("copy_newc", "-H newc", "", result, "2 blocks\n"); + basic_cpio("copy_cpio", "-H odc", "", msg, msg); msg = canSymlink() ? "9 blocks\n" : "8 blocks\n"; - basic_cpio("copy_ustar", "-H ustar", "", msg); + basic_cpio("copy_ustar", "-H ustar", "", msg, msg); /* Copy in one step using -p */ passthrough("passthrough"); diff --git a/cpio/test/test_format_newc.c b/cpio/test/test_format_newc.c index 06749a2f9..e1047e5b4 100644 --- a/cpio/test/test_format_newc.c +++ b/cpio/test/test_format_newc.c @@ -77,6 +77,7 @@ DEFINE_TEST(test_format_newc) time_t t, t2, now; char *p, *e; size_t s, fs, ns; + char result[1024]; assertUmask(0); @@ -111,6 +112,29 @@ DEFINE_TEST(test_format_newc) assertMakeDir("dir", 0775); fprintf(list, "dir\n"); + /* Setup result message. */ + memset(result, 0, sizeof(result)); + if (is_LargeInode("file1")) + strncat(result, + "bsdcpio: file1: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result) -1); + if (canSymlink() && is_LargeInode("symlink")) + strncat(result, + "bsdcpio: symlink: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result) -1); + if (is_LargeInode("dir")) + strncat(result, + "bsdcpio: dir: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result) -1); + if (is_LargeInode("hardlink")) + strncat(result, + "bsdcpio: hardlink: large inode number truncated: " + "Numerical result out of range\n", + sizeof(result) - strlen(result) -1); + /* Record some facts about what we just created: */ now = time(NULL); /* They were all created w/in last two seconds. */ @@ -123,10 +147,11 @@ DEFINE_TEST(test_format_newc) /* Verify that nothing went to stderr. */ if (canSymlink()) { - assertTextFileContents("2 blocks\n", "newc.err"); + strncat(result, "2 blocks\n", sizeof(result) - strlen(result)); } else { - assertTextFileContents("1 block\n", "newc.err"); + strncat(result, "1 block\n", sizeof(result) - strlen(result)); } + assertTextFileContents(result, "newc.err"); /* Verify that stdout is a well-formed cpio file in "newc" format. */ p = slurpfile(&s, "newc.out");