Adds some check about options compatibility.

This commit is contained in:
Andrea Mazzoleni 2012-10-14 10:02:22 +02:00
parent 5ddbd1a6a0
commit 4ed9e0803f
4 changed files with 79 additions and 38 deletions

View file

@ -364,25 +364,27 @@ the file \(a"/etc/snapraid.conf\(a" in Unix, and \(a"snapraid.conf\(a" in
the current directory in Windows.
.TP
.B \(hyf, \(hy\(hyfilter PATTERN
Filters the files to operate on with the \(a"check\(a" and \(a"fix\(a"
Filters the files to process in the \(a"check\(a" and \(a"fix\(a"
commands.
This option cannot be used with the \(a"sync\(a" command.
Only the files matching the entered pattern are processed.
This option can be used many times.
See the PATTERN section for more details in the
pattern specifications.
This option can be used many times.
In Unix, ensure to quote globbing chars if used.
This option can be used only with the \(a"check\(a" and \(a"fix\(a" commands.
Note that it cannot be used with \(a"sync\(a", because \(a"sync\(a" always
process the whole array.
.TP
.B \(hyd, \(hy\(hyfilter\(hydisk NAME
Filters the files to operate on with the \(a"check\(a" and \(a"fix\(a"
Filters the files to process in the \(a"check\(a" and \(a"fix\(a"
commands.
This option cannot be used with the \(a"sync\(a" command.
You must specify a disk name as named in the configuration
file.
.TP
.B \(hyH, \(hy\(hyfilter\(hynohidden
Filters out hidden files and directory. In Unix hidden files are
the ones starting with \(cq.\(cq. In Windows they are the ones with the
hidden attribute.
Excludes hidden files and directory.
In Unix hidden files are the ones starting with \(cq.\(cq.
In Windows they are the ones with the hidden attribute.
.TP
.B \(hya, \(hy\(hyaudit\(hyonly
When checking, only verify the hash of the files, without
@ -401,7 +403,7 @@ and not resynched.
Note that if you use this option, all the hard\(hylinks will be
stored independently wasting space. So, if you use hard\(hylinks,
it\(cqs better to don\(cqt use it.
This option has effect only on the \(a"sync\(a" and \(a"diff\(a" commands.
This option can be used only with the \(a"sync\(a" and \(a"diff\(a" commands.
.TP
.B \(hyZ, \(hy\(hyforce\(hyzero
Forces the insecure operation of syncing a file with zero
@ -412,6 +414,7 @@ This allows to easily detect when after a system crash,
some accessed files were zeroed.
This is a possible condition in Linux with the ext3/ext4
filesystems.
This option can be used only with the \(a"sync\(a" command.
.TP
.B \(hyE, \(hy\(hyforce\(hyempty
Forces the insecure operation of syncing a disk with all
@ -421,6 +424,7 @@ in the disk are missing or rewritten, it stops proceeding
unless you specify this option.
This allows to easily detect when a data file\(hysystem is not
mounted.
This option can be used only with the \(a"sync\(a" command.
.TP
.B \(hys, \(hy\(hystart BLKSTART
Starts the processing from the specified

View file

@ -145,6 +145,7 @@ int main(int argc, char* argv[])
int ret;
tommy_list filterlist;
char* e;
const char* command;
os_init();
@ -264,7 +265,8 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
if (strcmp(argv[optind], "diff") == 0) {
command = argv[optind];
if (strcmp(command, "diff") == 0) {
operation = OPERATION_DIFF;
} else if (strcmp(argv[optind], "sync") == 0) {
operation = OPERATION_SYNC;
@ -281,6 +283,40 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
/* check options compatibility */
switch (operation) {
case OPERATION_CHECK :
break;
default:
if (audit_only) {
fprintf(stderr, "You cannot use -A, --audit-only with the '%s' command\n", command);
exit(EXIT_FAILURE);
}
}
switch (operation) {
case OPERATION_SYNC :
case OPERATION_DIFF :
break;
default:
if (find_by_name) {
fprintf(stderr, "You cannot use -N, --find-by-name with the '%s' command\n", command);
exit(EXIT_FAILURE);
}
}
switch (operation) {
case OPERATION_CHECK :
case OPERATION_FIX :
case OPERATION_DRY :
break;
default:
if (!tommy_list_empty(&filterlist)) {
fprintf(stderr, "You cannot filter with the '%s' command\n", command);
exit(EXIT_FAILURE);
}
}
raid_init();
if (!test_skip_self)
@ -295,11 +331,6 @@ int main(int argc, char* argv[])
state_scan(&state, 1);
} else if (operation == OPERATION_SYNC) {
if (!tommy_list_empty(&filterlist)) {
fprintf(stderr, "You cannot filter with the sync command\n");
exit(EXIT_FAILURE);
}
state_read(&state);
state_scan(&state, 0);
@ -356,9 +387,6 @@ int main(int argc, char* argv[])
} else if (operation == OPERATION_DUP) {
state_read(&state);
/* apply the command line filter */
state_filter(&state, &filterlist);
state_dup(&state);
} else {
state_read(&state);
@ -369,10 +397,11 @@ int main(int argc, char* argv[])
/* intercept Ctrl+C */
signal(SIGINT, &signal_handler);
if (operation == OPERATION_CHECK)
if (operation == OPERATION_CHECK) {
state_check(&state, !audit_only, 0, blockstart, blockcount);
else /* it's fix */
} else { /* it's fix */
state_check(&state, 1, 1, blockstart, blockcount);
}
}
state_done(&state);

View file

@ -238,25 +238,27 @@ Options
the current directory in Windows.
-f, --filter PATTERN
Filters the files to operate on with the "check" and "fix"
Filters the files to process in the "check" and "fix"
commands.
This option cannot be used with the "sync" command.
Only the files matching the entered pattern are processed.
This option can be used many times.
See the PATTERN section for more details in the
pattern specifications.
This option can be used many times.
In Unix, ensure to quote globbing chars if used.
This option can be used only with the "check" and "fix" commands.
Note that it cannot be used with "sync", because "sync" always
process the whole array.
-d, --filter-disk NAME
Filters the files to operate on with the "check" and "fix"
Filters the files to process in the "check" and "fix"
commands.
This option cannot be used with the "sync" command.
You must specify a disk name as named in the configuration
file.
-H, --filter-nohidden
Filters out hidden files and directory. In Unix hidden files are
the ones starting with '.'. In Windows they are the ones with the
hidden attribute.
Excludes hidden files and directory.
In Unix hidden files are the ones starting with '.'.
In Windows they are the ones with the hidden attribute.
-a, --audit-only
When checking, only verify the hash of the files, without
@ -275,7 +277,7 @@ Options
Note that if you use this option, all the hard-links will be
stored independently wasting space. So, if you use hard-links,
it's better to don't use it.
This option has effect only on the "sync" and "diff" commands.
This option can be used only with the "sync" and "diff" commands.
-Z, --force-zero
Forces the insecure operation of syncing a file with zero
@ -286,6 +288,7 @@ Options
some accessed files were zeroed.
This is a possible condition in Linux with the ext3/ext4
filesystems.
This option can be used only with the "sync" command.
-E, --force-empty
Forces the insecure operation of syncing a disk with all
@ -295,6 +298,7 @@ Options
unless you specify this option.
This allows to easily detect when a data file-system is not
mounted.
This option can be used only with the "sync" command.
-s, --start BLKSTART
Starts the processing from the specified

View file

@ -267,25 +267,27 @@ SnapRAID provides the following options:
the current directory in Windows.
-f, --filter PATTERN
Filters the files to operate on with the "check" and "fix"
Filters the files to process in the "check" and "fix"
commands.
This option cannot be used with the "sync" command.
Only the files matching the entered pattern are processed.
This option can be used many times.
See the PATTERN section for more details in the
pattern specifications.
This option can be used many times.
In Unix, ensure to quote globbing chars if used.
This option can be used only with the "check" and "fix" commands.
Note that it cannot be used with "sync", because "sync" always
process the whole array.
-d, --filter-disk NAME
Filters the files to operate on with the "check" and "fix"
Filters the files to process in the "check" and "fix"
commands.
This option cannot be used with the "sync" command.
You must specify a disk name as named in the configuration
file.
-H, --filter-nohidden
Filters out hidden files and directory. In Unix hidden files are
the ones starting with '.'. In Windows they are the ones with the
hidden attribute.
Excludes hidden files and directory.
In Unix hidden files are the ones starting with '.'.
In Windows they are the ones with the hidden attribute.
-a, --audit-only
When checking, only verify the hash of the files, without
@ -304,7 +306,7 @@ SnapRAID provides the following options:
Note that if you use this option, all the hard-links will be
stored independently wasting space. So, if you use hard-links,
it's better to don't use it.
This option has effect only on the "sync" and "diff" commands.
This option can be used only with the "sync" and "diff" commands.
-Z, --force-zero
Forces the insecure operation of syncing a file with zero
@ -315,6 +317,7 @@ SnapRAID provides the following options:
some accessed files were zeroed.
This is a possible condition in Linux with the ext3/ext4
filesystems.
This option can be used only with the "sync" command.
-E, --force-empty
Forces the insecure operation of syncing a disk with all
@ -324,6 +327,7 @@ SnapRAID provides the following options:
unless you specify this option.
This allows to easily detect when a data file-system is not
mounted.
This option can be used only with the "sync" command.
-s, --start BLKSTART
Starts the processing from the specified