fix(delete): match rsync deletion semantics (#290)

- Scope the --delete extras walk to directories synchronized by the
  transfer: add a synchronized-directory section to the delete manifest
  (protocol 2.23.0) so --files-from subsets no longer delete untransmitted
  paths outside listed directory subtrees (data-loss fix).
- Separate --max-size/--min-size prune protection from --delete-excluded so
  size-pruned source mirrors survive (rsync parity).
- Unlink extraneous destination symlinks instead of skipping them.
- Make --max-delete partial (delete up to N, skip the rest) and exit 25;
  accept negative values as unlimited.
- Draw --delete-missing-args deletions from the shared --max-delete budget.
- Honor --force during --delay-updates publication.

Add unit and integration regression tests; update the pinned config wire
golden and version strings for the 2.23.0 manifest/status additions.
This commit is contained in:
2026-09-15 23:12:03 +02:00
parent 23552e823d
commit 82a1d5e240
28 changed files with 1159 additions and 438 deletions
+28 -3
View File
@@ -234,6 +234,25 @@ static int set_nonneg_int_option(int* dest, const char* value, const char* optio
return 0;
}
/* Parse a signed integer, clamping every negative value to -1. rsync's
--max-delete treats a negative argument (the deprecated -1 spelling) as "no
client limit", so -2/-5 must behave identically rather than being rejected. */
static int set_signed_clamped_int_option(int* dest, const char* value, const char* option_name) {
if (!value || *value == '\0') {
log_message(LOG_LEVEL_ERROR, "%s must be an integer", option_name);
return -1;
}
char* endptr;
errno = 0;
long parsed = strtol(value, &endptr, 10);
if (errno != 0 || *endptr != '\0' || parsed < INT_MIN || parsed > INT_MAX) {
log_message(LOG_LEVEL_ERROR, "%s must be an integer", option_name);
return -1;
}
*dest = parsed < 0 ? -1 : (int)parsed;
return 0;
}
/* Forward decl: config_add_pattern is defined below, but the --remote-option
* helper above needs it. */
static int config_add_pattern(char*** patterns, int* count, const char* value, const char* optname);
@@ -603,6 +622,9 @@ typedef enum {
OPT_POS_INT,
OPT_NONNEG_INT,
OPT_ULL,
/* A signed integer whose negative values are clamped to -1 (rsync's
"no limit" spelling for --max-delete). */
OPT_SIGNED_INT,
} OptKind;
typedef struct {
@@ -717,7 +739,7 @@ static const OptionEntry OPTION_TABLE[] = {
{"--delete-delay", NULL, OPT_FLAG, offsetof(Config, delete_delay)},
{"--delete-after", NULL, OPT_FLAG, offsetof(Config, delete_after)},
{"--delete-excluded", NULL, OPT_FLAG, offsetof(Config, delete_excluded)},
{"--max-delete", NULL, OPT_NONNEG_INT, offsetof(Config, max_delete)},
{"--max-delete", NULL, OPT_SIGNED_INT, offsetof(Config, max_delete)},
{"--ignore-errors", NULL, OPT_FLAG, offsetof(Config, ignore_errors)},
{"--force", NULL, OPT_FLAG, offsetof(Config, force_delete)},
{"--prune-empty-dirs", "-m", OPT_FLAG, offsetof(Config, prune_empty_dirs)},
@@ -840,7 +862,8 @@ static const OptionEntry* find_table_option_with_equals(const char* arg, const c
(entry->alias && strlen(entry->alias) == name_len &&
strncmp(arg, entry->alias, name_len) == 0)) {
if (entry->kind == OPT_STRING || entry->kind == OPT_POS_INT ||
entry->kind == OPT_NONNEG_INT || entry->kind == OPT_ULL) {
entry->kind == OPT_NONNEG_INT || entry->kind == OPT_ULL ||
entry->kind == OPT_SIGNED_INT) {
*value = equals + 1;
return entry;
}
@@ -908,6 +931,8 @@ static int apply_table_option(Config* config, const OptionEntry* entry, const ch
return set_positive_int_option((int*)field, value, entry->name);
case OPT_NONNEG_INT:
return set_nonneg_int_option((int*)field, value, entry->name);
case OPT_SIGNED_INT:
return set_signed_clamped_int_option((int*)field, value, entry->name);
case OPT_ULL: {
unsigned long long v;
/* Size-limit options accept rsync-style suffixes (e.g. --max-size=2G); a
@@ -2109,7 +2134,7 @@ static bool cli_long_takes_separate_value(const char* arg) {
const OptionEntry* entry = find_table_option(arg);
if (entry)
return entry->kind == OPT_STRING || entry->kind == OPT_POS_INT ||
entry->kind == OPT_NONNEG_INT || entry->kind == OPT_ULL;
entry->kind == OPT_NONNEG_INT || entry->kind == OPT_ULL || entry->kind == OPT_SIGNED_INT;
static const char* const extra[] = {
"--ssh-port", "--exclude", "--include", "--exclude-from",
"--include-from", "--files-from", "--filter", "--delta-block",