From fe5ff734f72771cecaa76c1cef8d411cb19f2949 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 3 Sep 2026 16:35:16 +0200 Subject: [PATCH] Persist content state and bad block markings on sync errors while preserving deallocation state --- cmdline/sync.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cmdline/sync.c b/cmdline/sync.c index c1f92bc3..7cf72ac4 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -2155,21 +2155,32 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t } /* - * On close errors, abort without committing or persisting state, - * keeping the previous content file intact for recovery on the next run. + * Only a clean full sync makes all deallocation records obsolete. + * + * When process_error == 0, parity has been fully updated without the deleted + * files, so state_commit() clears the dealloclist. + * + * If any error occurred, state_commit() is skipped so the dealloclist remains + * intact. Calling state_write() below will then persist both the accumulated + * deallocation records and any error markings to the content file, keeping + * recovery data available across consecutive interrupted or failed runs. */ - if (process_error != 0) - return -1; + if (process_error == 0) { + msg_status("Everything OK\n"); - msg_status("Everything OK\n"); + state_commit(state); + } - /* only a clean full sync makes all deallocation records obsolete */ - state_commit(state); - - /* persist progress and error markings only after all parity handles are closed */ + /* + * Persist progress, error markings, and pending deallocations only after + * all parity handles are closed. + */ if (state->need_write || state->opt.force_content_write) state_write(state); + if (process_error != 0) + return -1; + return 0; }