]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Consider the large i-node number for the tests using cpio newc format.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 13 Apr 2011 10:43:55 +0000 (06:43 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 13 Apr 2011 10:43:55 +0000 (06:43 -0400)
Some cpio tests on Cygwin 1.7.x always failed because of the large i-node number.

SVN-Revision: 3222

cpio/test/main.c
cpio/test/test.h
cpio/test/test_basic.c
cpio/test/test_format_newc.c

index c0166f6929840836aace674afdfe7319ca3d5e11..78f11e63a489c45a575464c536e080b962d77fd5 100644 (file)
@@ -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
index a552c8f5b955be8b6fa6a6f8fd143ced7c95cbfd..05fa2c3810f555bfe9f416ac3b8379cb7f35cee3 100644 (file)
@@ -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, ...);
index 1a38104611ff95ccc63559e025543594398429de..c40813e9a26ff596a1df86c69b40093c5607190b 100644 (file)
@@ -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");
index 06749a2f9caa2cc3f3a20d68b0e1708cd896f71e..e1047e5b4e93cb50342d2d9848e096b02c35984f 100644 (file)
@@ -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");