diff --git a/cmdline/check.c b/cmdline/check.c index a8d56fc3..3dc61485 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1822,6 +1822,26 @@ static int file_recover(struct snapraid_state* state, int fix, int partial, bloc /* LCOV_EXCL_STOP */ } + /* + * A recovery write changes the file modification time. With syncedonly, + * later recovery writes are allowed only while the file still matches + * the metadata stored in the content file. Restore the original mtime + * after every successful write so an interruption between blocks does + * not make a partially recovered file appear unsynced on the next run. + */ + if (state->opt.syncedonly) { + ret = handle_utime(failed[j].handle); + if (ret == -1) { + /* LCOV_EXCL_START */ + file_flag_set(failed[j].file, FILE_IS_DAMAGED); + log_tag("%s:%" PRIu64 ":%s:%s: Time error. %s.\n", es(errno), block_pos, failed[j].disk->name, esc_tag(failed[j].file->sub), strerror(errno)); + log_fatal_errno(errno, failed[j].disk->name); + log_fatal(errno, "Stopping at block %" PRIu64 "\n", block_pos); + return -1; + /* LCOV_EXCL_STOP */ + } + } + /* if we are not sure that the recovered content is uptodate */ if (failed[j].recovery == RECOVERY_OUTOFDATE) continue; diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 337f17f7..e5a53d98 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1280,6 +1280,20 @@ int snapraid_main(int argc, char* argv[]) /* LCOV_EXCL_STOP */ } + if (opt.syncedonly && blockstart_set) { + /* LCOV_EXCL_START */ + log_fatal(EUSER, "You cannot use -S, --start with -e, --filter-error or -b, --filter-block-error\n"); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + + if (opt.syncedonly && blockcount_set) { + /* LCOV_EXCL_START */ + log_fatal(EUSER, "You cannot use -B, --count with -e, --filter-error or -b, --filter-block-error\n"); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + if (opt.prehash && opt.force_nocopy) { /* LCOV_EXCL_START */ log_fatal(EUSER, "You cannot use the -h, --pre-hash and -N, --force-nocopy options simultaneously\n");