diff --git a/HISTORY b/HISTORY index 0547192e..e925bb41 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,12 @@ SnapRAID HISTORY ================ +8.1 2015/05 +=========== + * Fix builds issues in generic Unix platforms. + * The "diff" command returns with error code 2 if a "sync" is + required, to differentiate with the generic error code 1. + 8.0 2015/04 =========== * Allows "sync" and "scrub" to continue after the first bunch of disk diff --git a/Makefile.am b/Makefile.am index f1745904..dba84751 100644 --- a/Makefile.am +++ b/Makefile.am @@ -231,13 +231,13 @@ endif echo DUP > bench/disk1/DUP2 echo --- Some commands with a not empty array # Run a sync using physical offset - $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_PHYSICAL) -c $(CONF) --test-expect-failure diff > output.log + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_PHYSICAL) -c $(CONF) --test-expect-need-sync diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_PHYSICAL) -c $(CONF) sync # Now reset the array, as we normally test with alpha order and murmur3 rm bench/content bench/?-content # Now rebuild the array with alpha order and murmur3 and do some commands # Later we will convert it to spooky2 to test both hashes - $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure diff > output.log + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-need-sync diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-murmur3 --test-force-autosave-at 100 sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) dup -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) list -l test.log > output.log @@ -274,14 +274,14 @@ endif rm bench/disk4/a/9* rm bench/disk5/a/9* rm bench/disk6/a/9* - $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure diff > output.log + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-need-sync diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) sync -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check echo --- Move some files, sync and check mv bench/disk1/a/9* bench/disk4/a mv bench/disk2/a/9* bench/disk5/a mv bench/disk3/a/9* bench/disk6/a - $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure diff > output.log + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-need-sync diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) check echo --- Create some more files, hardlinks and empty directories, delete others, sync PAR1 and check @@ -303,7 +303,7 @@ endif echo 333 > bench/disk3/file_hardlink1 ln bench/disk3/file_hardlink1 bench/disk3/file_hardlink2 ln bench/disk3/file_hardlink1 bench/disk3/file_hardlink3 - $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) --test-expect-failure diff > output.log + $(FAILENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) --test-expect-need-sync diff > output.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-fallocate -c $(PAR1) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-sequential -c $(PAR1) check diff --git a/cmdline/mingw.c b/cmdline/mingw.c index ee688ba5..f4cf3c1e 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -22,10 +22,11 @@ #include "support.h" /** - * Standard exit codes. + * Exit codes. */ int exit_success = 0; int exit_failure = 1; +int exit_sync_needed = 2; /* Adds missing Windows declaration */ typedef struct _FILE_ATTRIBUTE_TAG_INFO { diff --git a/cmdline/portable.h b/cmdline/portable.h index a7ca6237..a6b91bd7 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -336,10 +336,12 @@ FILE* stdlog; */ int exit_success; int exit_failure; +int exit_sync_needed; #undef EXIT_SUCCESS #undef EXIT_FAILURE #define EXIT_SUCCESS exit_success #define EXIT_FAILURE exit_failure +#define EXIT_SYNC_NEEDED exit_sync_needed /** * Fill memory with psudeo-random values. diff --git a/cmdline/scan.c b/cmdline/scan.c index 055cfed1..87a3e4a4 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -1748,11 +1748,11 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (is_diff) { /* check for file difference */ if (!no_difference) - return -1; + return 1; /* check also for incomplete "sync" */ if (parity_is_invalid(state)) - return -1; + return 1; } return 0; diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index b3d86ef1..9d935812 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -245,6 +245,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_SKIP_DISK_ACCESS 282 #define OPT_TEST_FORCE_AUTOSAVE_AT 283 #define OPT_TEST_FAKE_DEVICE 284 +#define OPT_TEST_EXPECT_NEED_SYNC 285 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -338,6 +339,9 @@ struct option long_options[] = { /* Exit generic failure */ { "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE }, + /* Exit generic need sync */ + { "test-expect-need-sync", 0, 0, OPT_TEST_EXPECT_NEED_SYNC }, + /* Run some command after loading the state and before the command */ { "test-run", 1, 0, OPT_TEST_RUN }, @@ -675,10 +679,15 @@ int main(int argc, char* argv[]) opt.force_content_text = 1; break; case OPT_TEST_EXPECT_FAILURE : - /* invert the exit code */ + /* invert the exit codes */ exit_success = 1; exit_failure = 0; break; + case OPT_TEST_EXPECT_NEED_SYNC : + /* invert the exit codes */ + exit_success = 1; + exit_sync_needed = 0; + break; case OPT_TEST_RUN : run = optarg; break; @@ -975,12 +984,9 @@ int main(int argc, char* argv[]) ret = state_diff(&state); - /* abort if required */ - if (ret != 0) { - /* LCOV_EXCL_START */ - exit(EXIT_FAILURE); - /* LCOV_EXCL_STOP */ - } + /* abort if sync needed */ + if (ret > 0) + exit(EXIT_SYNC_NEEDED); } else if (operation == OPERATION_SYNC) { /* in the next state read ensures to clear all the past hashes in case */ diff --git a/cmdline/unix.c b/cmdline/unix.c index c67a6f50..01c7c79c 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -22,10 +22,11 @@ #include "support.h" /** - * Standard exit codes. + * Exit codes. */ int exit_success = 0; int exit_failure = 1; +int exit_sync_needed = 2; int open_noatime(const char* file, int flags) { diff --git a/snapraid.1 b/snapraid.1 index 7c8e4c58..74d96200 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -725,8 +725,8 @@ their parity data recomputed. This command doesn\'t check the file data, but only the file timestamp size and inode. .PP -If a \[dq]sync\[dq] is not required, the return error code is 0. Otherwise, -it\'s 1. +If a \[dq]sync\[dq] is required, the process return code is 2, instead of the +default 0. The return code 1 is instead for a generic error condition. .PP Nothing is modified. .SS sync diff --git a/snapraid.d b/snapraid.d index bb6ea067..3508eb17 100644 --- a/snapraid.d +++ b/snapraid.d @@ -437,8 +437,8 @@ Commands This command doesn't check the file data, but only the file timestamp size and inode. - If a "sync" is not required, the return error code is 0. Otherwise, - it's 1. + If a "sync" is required, the process return code is 2, instead of the + default 0. The return code 1 is instead for a generic error condition. Nothing is modified. diff --git a/snapraid.txt b/snapraid.txt index a110da35..5d32daa4 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -471,8 +471,8 @@ their parity data recomputed. This command doesn't check the file data, but only the file timestamp size and inode. -If a "sync" is not required, the return error code is 0. Otherwise, -it's 1. +If a "sync" is required, the process return code is 2, instead of the +default 0. The return code 1 is instead for a generic error condition. Nothing is modified.