]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
On Windows, pass test_option_a in bsdcpio_test.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 11 Mar 2009 09:38:00 +0000 (05:38 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 11 Mar 2009 09:38:00 +0000 (05:38 -0400)
- Tweak cpio; close a file descriptor to restore access times
  before we call lutimes/utimes function.

SVN-Revision: 759

cpio/cpio.c
cpio/test/test_option_a.c

index 15302703e524aceba2a62c95db2b3c7bc8f7234d..4b9b60dedf992c824046f4e7edfb8824799eaa2d 100644 (file)
@@ -100,7 +100,7 @@ static void mode_in(struct cpio *);
 static void    mode_list(struct cpio *);
 static void    mode_out(struct cpio *);
 static void    mode_pass(struct cpio *, const char *);
-static void    restore_time(struct cpio *, struct archive_entry *,
+static int     restore_time(struct cpio *, struct archive_entry *,
                    const char *, int fd);
 static void    usage(void);
 static void    version(void);
@@ -680,7 +680,7 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
                }
        }
 
-       restore_time(cpio, entry, srcpath, fd);
+       fd = restore_time(cpio, entry, srcpath, fd);
 
 cleanup:
        if (cpio->verbose)
@@ -690,7 +690,7 @@ cleanup:
        return (0);
 }
 
-static void
+static int
 restore_time(struct cpio *cpio, struct archive_entry *entry,
     const char *name, int fd)
 {
@@ -700,12 +700,11 @@ restore_time(struct cpio *cpio, struct archive_entry *entry,
        (void)cpio; /* UNUSED */
        (void)entry; /* UNUSED */
        (void)name; /* UNUSED */
-       (void)fd; /* UNUSED */
 
        if (!warned)
                cpio_warnc(0, "Can't restore access times on this platform");
        warned = 1;
-       return;
+       return (fd);
 #else
 #ifdef _WIN32
        struct __timeval times[2];
@@ -714,7 +713,7 @@ restore_time(struct cpio *cpio, struct archive_entry *entry,
 #endif
 
        if (!cpio->option_atime_restore)
-               return;
+               return (fd);
 
         times[1].tv_sec = archive_entry_mtime(entry);
         times[1].tv_usec = archive_entry_mtime_nsec(entry) / 1000;
@@ -724,8 +723,16 @@ restore_time(struct cpio *cpio, struct archive_entry *entry,
 
 #ifdef HAVE_FUTIMES
         if (fd >= 0 && futimes(fd, times) == 0)
-               return;
+               return (fd);
 #endif
+       /*
+        * Some platform cannot restore access times if the file descriptor
+        * is still opened.
+        */
+       if (fd >= 0) {
+               close(fd);
+               fd = -1;
+       }
 
 #ifdef HAVE_LUTIMES
         if (lutimes(name, times) != 0)
@@ -734,6 +741,7 @@ restore_time(struct cpio *cpio, struct archive_entry *entry,
 #endif
                 cpio_warnc(errno, "Can't update time for %s", name);
 #endif
+       return (fd);
 }
 
 
index 324706c45fb280457e7d84321e2b0d419b438fdd..154cc3a871625b72a94668c2f10e8be8d051d53c 100644 (file)
@@ -99,6 +99,7 @@ DEFINE_TEST(test_option_a)
        int r;
        int f;
        char buff[64];
+       const char *p;
 
        /* Create all of the test files. */
        test_create();
@@ -122,7 +123,8 @@ DEFINE_TEST(test_option_a)
                /* Copy the file without -a; should change the atime. */
                r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog);
                assertEqualInt(r, 0);
-               assertFileContents("1 block\n", 8, "copy-no-a.err");
+               p = "1 block" NL;
+               assertFileContents(p, strlen(p), "copy-no-a.err");
                assertEmptyFile("copy-no-a.out");
                assertEqualInt(0, stat(files[1].name, &st));
                failure("Copying file without -a should have changed atime.");
@@ -131,7 +133,7 @@ DEFINE_TEST(test_option_a)
                /* Archive the file without -a; should change the atime. */
                r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog);
                assertEqualInt(r, 0);
-               assertFileContents("1 block\n", 8, "copy-no-a.err");
+               assertFileContents(p, strlen(p), "copy-no-a.err");
                assertEqualInt(0, stat(files[2].name, &st));
                failure("Archiving file without -a should have changed atime.");
                assert(st.st_atime != files[2].atime_sec);
@@ -146,7 +148,8 @@ DEFINE_TEST(test_option_a)
        r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err",
            files[3].name, testprog);
        assertEqualInt(r, 0);
-       assertFileContents("1 block\n", 8, "copy-a.err");
+       p = "1 block" NL;
+       assertFileContents(p, strlen(p), "copy-a.err");
        assertEmptyFile("copy-a.out");
        assertEqualInt(0, stat(files[3].name, &st));
        failure("Copying file with -a should not have changed atime.");
@@ -156,7 +159,7 @@ DEFINE_TEST(test_option_a)
        r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err",
            files[4].name, testprog);
        assertEqualInt(r, 0);
-       assertFileContents("1 block\n", 8, "copy-a.err");
+       assertFileContents(p, strlen(p), "copy-a.err");
        assertEqualInt(0, stat(files[4].name, &st));
        failure("Archiving file with -a should not have changed atime.");
        assertEqualInt(st.st_atime, files[4].atime_sec);