]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Compare full file flags in test_option_fflags
authorMartin Matuska <martin@matuska.org>
Tue, 28 Feb 2017 16:01:38 +0000 (17:01 +0100)
committerMartin Matuska <martin@matuska.org>
Tue, 28 Feb 2017 16:01:38 +0000 (17:01 +0100)
tar/test/test_option_fflags.c
test_utils/test_common.h
test_utils/test_main.c

index ab62186e3ef4e4f02d0deca89de597217c3fdc55..72fc7ce85644141f998b34e7155c081627830939 100644 (file)
@@ -52,23 +52,23 @@ DEFINE_TEST(test_option_fflags)
        assertMakeDir("fflags_fflags", 0755);
        r = systemf("%s -x -C fflags_fflags --no-same-permissions --fflags -f fflags.tar >fflags_fflags.out 2>fflags_fflags.err", testprog);
        assertEqualInt(r, 0);
-       assertHasNodump("fflags_fflags/f", 1);
+       assertEqualFflags("f", "fflags_fflags/f");
 
        /* Extract fflags without fflags */
        assertMakeDir("fflags_nofflags", 0755);
        r = systemf("%s -x -C fflags_nofflags -p --no-fflags -f fflags.tar >fflags_nofflags.out 2>fflags_nofflags.err", testprog);
        assertEqualInt(r, 0);
-       assertHasNodump("fflags_nofflags/f", 0);
+       assertUnequalFflags("f", "fflags_nofflags/f");
 
        /* Extract nofflags with fflags */
        assertMakeDir("nofflags_fflags", 0755);
        r = systemf("%s -x -C nofflags_fflags --no-same-permissions --fflags -f nofflags.tar >nofflags_fflags.out 2>nofflags_fflags.err", testprog);
        assertEqualInt(r, 0);   
-       assertHasNodump("nofflags_fflags/f", 0);
+       assertUnequalFflags("f", "nofflags_fflags/f");
 
        /* Extract nofflags with nofflags */
        assertMakeDir("nofflags_nofflags", 0755);
        r = systemf("%s -x -C nofflags_nofflags -p --no-fflags -f nofflags.tar >nofflags_nofflags.out 2>nofflags_nofflags.err", testprog);
        assertEqualInt(r, 0);
-       assertHasNodump("nofflags_nofflags/f", 0);
+       assertUnequalFflags("f", "nofflags_nofflags/f");
 }
index ce06f4e9d6622fdf3295daf65e8600fb7b509330..88ef04c39801f71c95adbf8df15513eadcb8c346 100644 (file)
 /* chdir() and error if it fails */
 #define assertChdir(path)  \
   assertion_chdir(__FILE__, __LINE__, path)
+/* Assert two files have the same file flags */
+#define assertEqualFflags(patha, pathb)        \
+  assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 0)
 /* Assert two integers are the same.  Reports value of each one if not. */
 #define assertEqualInt(v1,v2) \
   assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
   assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
 #define assertMakeSymlink(newfile, linkto)     \
   assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
-#define assertHasNodump(path, isset)   \
-  assertion_has_nodump(__FILE__, __LINE__, path, isset)
 #define assertSetNodump(path)  \
   assertion_set_nodump(__FILE__, __LINE__, path)
 #define assertUmask(mask)      \
   assertion_umask(__FILE__, __LINE__, mask)
+/* Assert that two files have unequal file flags */
+#define assertUnequalFflags(patha, pathb)      \
+  assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 1)
 #define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec)   \
   assertion_utimes(__FILE__, __LINE__, pathname, atime, atime_nsec, mtime, mtime_nsec)
 #ifndef PROGRAM
 void failure(const char *fmt, ...);
 int assertion_assert(const char *, int, int, const char *, void *);
 int assertion_chdir(const char *, int, const char *);
+int assertion_compare_fflags(const char *, int, const char *, const char *,
+    int);
 int assertion_empty_file(const char *, int, const char *);
 int assertion_equal_file(const char *, int, const char *, const char *);
 int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
@@ -288,7 +294,6 @@ int assertion_file_mtime_recent(const char *, int, const char *);
 int assertion_file_nlinks(const char *, int, const char *, int);
 int assertion_file_not_exists(const char *, int, const char *);
 int assertion_file_size(const char *, int, const char *, long);
-int assertion_has_nodump(const char *, int, const char *, int);
 int assertion_is_dir(const char *, int, const char *, int);
 int assertion_is_hardlink(const char *, int, const char *, const char *);
 int assertion_is_not_hardlink(const char *, int, const char *, const char *);
index 8ae6c4448fb461c5de285629b1fa2d4d3bdaae8a..ec2fbfedcf4ef0fe5a71322de4edd3695ae446bf 100644 (file)
@@ -1882,34 +1882,45 @@ assertion_utimes(const char *file, int line,
        return (1);
 #endif /* defined(_WIN32) && !defined(__CYGWIN__) */
 }
-/* Get nodump. */
+
+/* Compare file flags */
 int
-assertion_has_nodump(const char *file, int line, const char *pathname, int isset)
+assertion_compare_fflags(const char *file, int line, const char *patha,
+    const char *pathb, int nomatch)
 {
 #if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
-       struct stat sb;
+       struct stat sa, sb;
 
        assertion_count(file, line);
 
-       if (stat(pathname, &sb) < 0)
+       if (stat(patha, &sa) < 0)
+               return (0);
+       if (stat(pathb, &sb) < 0)
+               return (0);
+       if (!nomatch && sa.st_flags != sb.st_flags) {
+               failure_start(file, line, "File flags should be identical: "
+                   "%s=%#010x %s=%#010x", patha, sa.st_flags, pathb,
+                   sb.st_flags);
+               failure_finish(NULL);
+               return (0);
+       }
+       if (nomatch && sa.st_flags == sb.st_flags) {
+               failure_start(file, line, "File flags should be different: "
+                   "%s=%#010x %s=%#010x", patha, sa.st_flags, pathb,
+                   sb.st_flags);
+               failure_finish(NULL);
                return (0);
-       if (sb.st_flags & UF_NODUMP) {
-               if (isset)
-                       return (1);
-       } else {
-               if (!isset)
-                       return (1);
        }
 #elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS) && \
        defined(FS_NODUMP_FL)) || \
       (defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) \
          && defined(EXT2_NODUMP_FL))
-       int fd, r, flags;
+       int fd, r, flagsa, flagsb;
 
        assertion_count(file, line);
-       fd = open(pathname, O_RDONLY | O_NONBLOCK);
+       fd = open(patha, O_RDONLY | O_NONBLOCK);
        if (fd < 0) {
-               failure_start(file, line, "Can't open %s\n", pathname);
+               failure_start(file, line, "Can't open %s\n", patha);
                failure_finish(NULL);
                return (0);
        }
@@ -1919,35 +1930,48 @@ assertion_has_nodump(const char *file, int line, const char *pathname, int isset
 #else
            EXT2_IOC_GETFLAGS,
 #endif
-           &flags);
+           &flagsa);
+       close(fd);
        if (r < 0) {
-               failure_start(file, line, "Can't get flags %s\n", pathname);
+               failure_start(file, line, "Can't get flags %s\n", patha);
                failure_finish(NULL);
                return (0);
        }
-#ifdef FS_NODUMP_FL
-       if (flags & FS_NODUMP_FL)
+       fd = open(pathb, O_RDONLY | O_NONBLOCK);
+       if (fd < 0) {
+               failure_start(file, line, "Can't open %s\n", pathb);
+               failure_finish(NULL);
+               return (0);
+       }
+       r = ioctl(fd,
+#ifdef FS_IOC_GETFLAGS
+           FS_IOC_GETFLAGS,
 #else
-       if (flags & EXT2_NODUMP_FL)
+           EXT2_IOC_GETFLAGS,
 #endif
-       {
-               if (!isset) {
-                       failure_start(file, line,
-                           "Nodump flag should not be set on %s\n", pathname);
-                       failure_finish(NULL);
-                       return (0);
-               }
-       } else {
-               if (isset) {
-                       failure_start(file, line,
-                           "Nodump flag should be set on %s\n", pathname);
-                       failure_finish(NULL);
-                       return (0);
-               }
+           &flagsb);
+       close(fd);
+       if (r < 0) {
+               failure_start(file, line, "Can't get flags %s\n", pathb);
+               failure_finish(NULL);
+               return (0);
+       }
+       if (!nomatch && flagsa != flagsb) {
+               failure_start(file, line, "File flags should be identical: "
+                   "%s=%#010x %s=%#010x", patha, flagsa, pathb, flagsb);
+               failure_finish(NULL);
+               return (0);
+       }
+       if (nomatch && flagsa == flagsb) {
+               failure_start(file, line, "File flags should be different: "
+                   "%s=%#010x %s=%#010x", patha, flagsa, pathb, flagsb);
+               failure_finish(NULL);
+               return (0);
        }
 #else
-       (void)pathname; /* UNUSED */
-       (void)isset; /* UNUSED */
+       (void)patha; /* UNUSED */
+       (void)pathb; /* UNUSED */
+       (void)nomatch; /* UNUSED */
        assertion_count(file, line);
 #endif
        return (1);