Compare full file flags in test_option_fflags
diff --git a/tar/test/test_option_fflags.c b/tar/test/test_option_fflags.c
index ab62186..72fc7ce 100644
--- a/tar/test/test_option_fflags.c
+++ b/tar/test/test_option_fflags.c
@@ -52,23 +52,23 @@
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");
}
diff --git a/test_utils/test_common.h b/test_utils/test_common.h
index ce06f4e..88ef04c 100644
--- a/test_utils/test_common.h
+++ b/test_utils/test_common.h
@@ -158,6 +158,9 @@
/* 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)
@@ -239,12 +242,13 @@
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
@@ -267,6 +271,8 @@
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_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 *);
diff --git a/test_utils/test_main.c b/test_utils/test_main.c
index 8ae6c44..ec2fbfe 100644
--- a/test_utils/test_main.c
+++ b/test_utils/test_main.c
@@ -1882,34 +1882,45 @@
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 (sb.st_flags & UF_NODUMP) {
- if (isset)
- return (1);
- } else {
- if (!isset)
- return (1);
+ 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);
}
#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 @@
#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);