Merge remote-tracking branch 'origin/feat/whole-file' into dev

# Conflicts:
#	tests/test_client_cli.c
#	tests/test_config.c
This commit is contained in:
2026-09-04 17:24:22 +02:00
10 changed files with 67 additions and 6 deletions
+1
View File
@@ -207,6 +207,7 @@ static const OptionEntry OPTION_TABLE[] = {
{"--delete", NULL, OPT_FLAG, offsetof(Config, use_delete)}, {"--delete", NULL, OPT_FLAG, offsetof(Config, use_delete)},
{"--incremental", NULL, OPT_FLAG, offsetof(Config, use_incremental)}, {"--incremental", NULL, OPT_FLAG, offsetof(Config, use_incremental)},
{"--delta", NULL, OPT_FLAG, offsetof(Config, use_delta)}, {"--delta", NULL, OPT_FLAG, offsetof(Config, use_delta)},
{"--whole-file", "-W", OPT_FLAG, offsetof(Config, whole_file)},
{"--save-to-disk", NULL, OPT_FLAG, offsetof(Config, save_to_disk)}, {"--save-to-disk", NULL, OPT_FLAG, offsetof(Config, save_to_disk)},
{"--progress", NULL, OPT_FLAG, offsetof(Config, show_progress)}, {"--progress", NULL, OPT_FLAG, offsetof(Config, show_progress)},
{"--tls", NULL, OPT_FLAG, offsetof(Config, use_tls)}, {"--tls", NULL, OPT_FLAG, offsetof(Config, use_tls)},
+1 -1
View File
@@ -435,7 +435,7 @@ static int send_single_file(Client* client, File* file, Config* config, bool use
delta_signature_destroy(sig); delta_signature_destroy(sig);
return 1; return 1;
} }
if (rc == 2 && config->use_delta) { if (rc == 2 && config->use_delta && !config->whole_file) {
int drc = send_delta(client, file, sig, config); int drc = send_delta(client, file, sig, config);
delta_signature_destroy(sig); delta_signature_destroy(sig);
if (drc == 0) if (drc == 0)
+3 -3
View File
@@ -23,15 +23,15 @@ bool validate_config(const Config* config) {
log_message(LOG_LEVEL_ERROR, "--incremental is not supported with -s (chunk serialization)"); log_message(LOG_LEVEL_ERROR, "--incremental is not supported with -s (chunk serialization)");
return false; return false;
} }
if (config->use_delta && !config->use_incremental) { if (config->use_delta && !config->whole_file && !config->use_incremental) {
log_message(LOG_LEVEL_ERROR, "--delta requires --incremental"); log_message(LOG_LEVEL_ERROR, "--delta requires --incremental");
return false; return false;
} }
if (config->use_delta && config->use_chunk_serialization) { if (config->use_delta && !config->whole_file && config->use_chunk_serialization) {
log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -s (chunk serialization)"); log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -s (chunk serialization)");
return false; return false;
} }
if (config->use_delta && config->use_sendfile) { if (config->use_delta && !config->whole_file && config->use_sendfile) {
log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -f (sendfile)"); log_message(LOG_LEVEL_ERROR, "--delta cannot be combined with -f (sendfile)");
return false; return false;
} }
+1
View File
@@ -31,6 +31,7 @@ void print_usage(void) {
printf(" --min-size <n> Skip files smaller than n bytes\n"); printf(" --min-size <n> Skip files smaller than n bytes\n");
printf(" --incremental Skip files unchanged since last transfer\n"); printf(" --incremental Skip files unchanged since last transfer\n");
printf(" --delta Delta transfer for changed files (requires --incremental)\n"); printf(" --delta Delta transfer for changed files (requires --incremental)\n");
printf(" -W, --whole-file Transfer changed files without delta processing\n");
printf(" --delta-block <n> Delta block size in bytes (default: %d)\n", printf(" --delta-block <n> Delta block size in bytes (default: %d)\n",
DELTA_BLOCK_SIZE_DEFAULT); DELTA_BLOCK_SIZE_DEFAULT);
printf(" --delta-max <n> Max file size for delta transfer (default: %llu)\n", printf(" --delta-max <n> Max file size for delta transfer (default: %llu)\n",
+2 -1
View File
@@ -36,6 +36,7 @@ static void config_set_defaults(Config* config) {
config->min_size = 0; config->min_size = 0;
config->use_incremental = false; config->use_incremental = false;
config->use_delta = false; config->use_delta = false;
config->whole_file = false;
config->delta_block_size = DELTA_BLOCK_SIZE_DEFAULT; config->delta_block_size = DELTA_BLOCK_SIZE_DEFAULT;
config->delta_max_file_size = DELTA_MAX_FILE_SIZE; config->delta_max_file_size = DELTA_MAX_FILE_SIZE;
config->use_tls = false; config->use_tls = false;
@@ -234,7 +235,7 @@ static bool send_core_fields(int fd, const Config* c) {
static bool send_delta_fields(int fd, const Config* c) { static bool send_delta_fields(int fd, const Config* c) {
return send_int(fd, c->use_delete) && send_int(fd, c->use_incremental) && return send_int(fd, c->use_delete) && send_int(fd, c->use_incremental) &&
send_int(fd, c->use_delta) && send_int(fd, c->use_delta && !c->whole_file) &&
send_n_data(fd, &c->delta_block_size, sizeof(c->delta_block_size)) && send_n_data(fd, &c->delta_block_size, sizeof(c->delta_block_size)) &&
send_n_data(fd, &c->delta_max_file_size, sizeof(unsigned long long)); send_n_data(fd, &c->delta_max_file_size, sizeof(unsigned long long));
} }
+1
View File
@@ -36,6 +36,7 @@ typedef struct Config {
unsigned long long min_size; unsigned long long min_size;
bool use_incremental; bool use_incremental;
bool use_delta; bool use_delta;
bool whole_file;
uint32_t delta_block_size; uint32_t delta_block_size;
unsigned long long delta_max_file_size; unsigned long long delta_max_file_size;
bool use_tls; bool use_tls;
+1 -1
View File
@@ -403,7 +403,7 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
return NULL; return NULL;
} }
bool try_delta = config->use_delta && has_old_file && old_data != NULL && bool try_delta = config->use_delta && !config->whole_file && has_old_file && old_data != NULL &&
delta_should_attempt(old_size, check_size, config->delta_max_file_size); delta_should_attempt(old_size, check_size, config->delta_max_file_size);
if (try_delta) { if (try_delta) {
+21
View File
@@ -331,6 +331,27 @@ class TestIncremental:
with open(received_file, "rb") as f: with open(received_file, "rb") as f:
assert f.read() == b"hello world\n" assert f.read() == b"hello world\n"
def test_whole_file_disables_delta_and_keeps_compression(self, shared_server):
clean_dir(DEST_DIR)
result, _ = run_client(SOURCE_DIR, DEST_DIR, flags=["-M"], port=shared_server.port)
assert result.returncode == 0
source_file = os.path.join(SOURCE_DIR, "medium.txt")
with open(source_file, "wb") as f:
f.write(b"whole-file replacement\n" * 5000)
result, _ = run_client(
SOURCE_DIR,
DEST_DIR,
flags=["-M", "--incremental", "--delta", "-W", "-c"],
port=shared_server.port,
)
assert result.returncode == 0, f"Whole-file sync failed: {(result.stderr or result.stdout)[:200]}"
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
mismatches, missing = verify_transfer(SOURCE_DIR, received)
assert not missing, f"Missing: {missing}"
assert not mismatches, f"Mismatch: {mismatches}"
class TestDelete: class TestDelete:
def test_delete_removes_extra_files(self, shared_server): def test_delete_removes_extra_files(self, shared_server):
+29
View File
@@ -60,6 +60,13 @@ static void test_validate_config_delta_sendfile_constraints() {
cfg->use_incremental = true; cfg->use_incremental = true;
cfg->use_sendfile = true; cfg->use_sendfile = true;
EXPECT_FALSE(validate_config(cfg)); EXPECT_FALSE(validate_config(cfg));
/* Whole-file makes delta selection inactive, so these combinations are valid. */
cfg->whole_file = true;
EXPECT_TRUE(validate_config(cfg));
cfg->use_incremental = false;
EXPECT_TRUE(validate_config(cfg));
config_delete(cfg); config_delete(cfg);
} }
@@ -507,6 +514,27 @@ static void test_parse_args_rejects_unsupported_stderr_modes() {
} }
log_set_stderr_mode(LOG_STDERR_ERRORS); log_set_stderr_mode(LOG_STDERR_ERRORS);
} }
/* Test both whole-file spellings and its precedence over delta selection. */
static void test_parse_args_whole_file() {
Config* cfg = config_create();
char* argv[] = {"fastsync", "--delta", "--incremental", "-W", "/src", "/dst"};
int positional_args[2];
int positional_count = 0;
EXPECT_EQ_INT(parse_args(cfg, 6, argv, positional_args, &positional_count), 0);
EXPECT_TRUE(cfg->whole_file);
EXPECT_TRUE(cfg->use_delta);
config_delete(cfg);
cfg = config_create();
char* long_argv[] = {"fastsync", "--whole-file", "/src", "/dst"};
positional_count = 0;
EXPECT_EQ_INT(parse_args(cfg, 4, long_argv, positional_args, &positional_count), 0);
EXPECT_TRUE(cfg->whole_file);
config_delete(cfg);
}
void test_client_cli() { void test_client_cli() {
test_validate_config_required_paths(); test_validate_config_required_paths();
test_validate_config_incompatible_options(); test_validate_config_incompatible_options();
@@ -541,4 +569,5 @@ void test_client_cli() {
test_parse_args_rejects_unsupported_stderr_modes(); test_parse_args_rejects_unsupported_stderr_modes();
test_parse_args_secluded_args(); test_parse_args_secluded_args();
test_parse_args_short_s_remains_chunk_serialization(); test_parse_args_short_s_remains_chunk_serialization();
test_parse_args_whole_file();
} }
+7
View File
@@ -125,6 +125,8 @@ static void test_config_send_receive() {
send_cfg->use_compression = true; send_cfg->use_compression = true;
send_cfg->use_metadata = true; send_cfg->use_metadata = true;
send_cfg->use_fsync = true; send_cfg->use_fsync = true;
send_cfg->use_delta = true;
send_cfg->whole_file = true;
send_cfg->compression_level = 5; send_cfg->compression_level = 5;
send_cfg->chunk_size = 1024; send_cfg->chunk_size = 1024;
send_cfg->eight_bit_output = true; send_cfg->eight_bit_output = true;
@@ -165,6 +167,11 @@ static void test_config_send_receive() {
if (!recv_cfg->use_fsync) if (!recv_cfg->use_fsync)
ok = false; ok = false;
if (!recv_cfg->eight_bit_output) if (!recv_cfg->eight_bit_output)
ok = false;
if (recv_cfg->use_delta)
ok = false;
if (!recv_cfg->whole_file)
ok = false;
} }
config_delete(recv_cfg); config_delete(recv_cfg);
close(p[0]); close(p[0]);