diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index b421db44..c3918d50 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1903,11 +1903,18 @@ int snapraid_main(int argc, char* argv[]) } else if (operation == OPERATION_REHASH) { state_read(&state); - /* intercept signals while operating */ - signal_init(); - state_rehash(&state); + /* + * Intercept signals while operating + * + * Intentionally do this after the touch operation. + * + * The signal protection is meant only for saving the content file, + * or an early stop of long operations. + */ + signal_init(); + /* save the new state if required */ if (state.need_write) state_write(&state); @@ -1945,10 +1952,18 @@ int snapraid_main(int argc, char* argv[]) state_touch(&state); - /* intercept signals while operating */ + /* + * Intercept signals while operating + * + * Intentionally do this after the touch operation. + * + * The signal protection is meant only for saving the content file, + * or an early stop of long operations. + */ signal_init(); - state_write(&state); + if (state.need_write) + state_write(&state); } else if (operation == OPERATION_SPINUP) { ret = state_device(&state, DEVICE_UP, &filterlist_disk); #if HAVE_CHECKER diff --git a/cmdline/touch.c b/cmdline/touch.c index 2acc54a6..8858c00d 100644 --- a/cmdline/touch.c +++ b/cmdline/touch.c @@ -11,6 +11,8 @@ void state_touch(struct snapraid_state* state) { tommy_node* i; + unsigned counter = 0; + msg_progress("Setting sub-second timestamps...\n"); /* for all disks */ @@ -72,7 +74,9 @@ void state_touch(struct snapraid_state* state) /* remove read only attribute */ if (windows_set_file_attributes(path, attributes & ~FILE_ATTRIBUTE_READONLY) == 0) { f = open(path, flags); - windows_set_file_attributes(path, attributes); + if (windows_set_file_attributes(path, attributes) != 0) { + log_error(errno, "Error restoring read-only attribute for '%s'. %s.\n", path, strerror(errno)); + } } } } @@ -139,8 +143,13 @@ void state_touch(struct snapraid_state* state) log_tag("touch:%s:%s: %" PRIu64 ".%d\n", disk->name, esc_tag(file->sub), (uint64_t)st.st_mtime, STAT_NSEC(&st)); msg_info("touch %s\n", fmt_term(disk, file->sub)); + + ++counter; } } } + + msg_status("\n"); + msg_status("%8u touched files\n", counter); }