Avoid saving the content file in touch if nothing changed

This commit is contained in:
Andrea Mazzoleni 2026-06-10 00:54:45 +02:00
parent e4aa186b1a
commit bf2657b76a
2 changed files with 30 additions and 6 deletions

View file

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

View file

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