Change the return code for 'diff' if a sync is required

This commit is contained in:
Andrea Mazzoleni 2015-04-28 19:15:16 +02:00
parent 9b4f41d7ff
commit 5c5e80a239
10 changed files with 38 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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 {

View file

@ -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.

View file

@ -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;

View file

@ -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 */

View file

@ -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)
{

View file

@ -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

View file

@ -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.

View file

@ -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.