diff --git a/RSYNC_COMPAT.md b/RSYNC_COMPAT.md index 4b224a1..bb64fbb 100644 --- a/RSYNC_COMPAT.md +++ b/RSYNC_COMPAT.md @@ -59,7 +59,7 @@ This document maps rsync's full feature set to FastSync's current implementation | `--max-size=SIZE` | Skip files larger than SIZE | ✅ Implemented | `max_size` in scanner | | `--min-size=SIZE` | Skip files smaller than SIZE | ✅ Implemented | `min_size` in scanner | | `-I`, `--ignore-times` | Don't skip files matching size+time | ❌ Not Implemented | | -| `--size-only` | Skip based on size only | ❌ Not Implemented | | +| `--size-only` | Skip based on size only | ✅ Implemented | With `--incremental`, ignores mtime | | `-@`, `--modify-window=NUM` | Mod-time comparison accuracy | ❌ Not Implemented | | | `--existing` | Skip creating new files on receiver | ❌ Not Implemented | | | `--ignore-existing` | Skip updating existing files | ❌ Not Implemented | | diff --git a/src/client/client_cli.c b/src/client/client_cli.c index 5fffe32..f359b6a 100644 --- a/src/client/client_cli.c +++ b/src/client/client_cli.c @@ -206,6 +206,7 @@ static const OptionEntry OPTION_TABLE[] = { {"--remove-source-files", NULL, OPT_FLAG, offsetof(Config, remove_source_files)}, {"--delete", NULL, OPT_FLAG, offsetof(Config, use_delete)}, {"--incremental", NULL, OPT_FLAG, offsetof(Config, use_incremental)}, + {"--size-only", NULL, OPT_FLAG, offsetof(Config, size_only)}, {"--ignore-times", "-I", OPT_FLAG, offsetof(Config, ignore_times)}, {"--delta", NULL, OPT_FLAG, offsetof(Config, use_delta)}, {"--whole-file", "-W", OPT_FLAG, offsetof(Config, whole_file)}, diff --git a/src/client/usage.c b/src/client/usage.c index 1d0aab3..079b871 100644 --- a/src/client/usage.c +++ b/src/client/usage.c @@ -30,6 +30,7 @@ void print_usage(void) { printf(" --max-size Skip files larger than n bytes\n"); printf(" --min-size Skip files smaller than n bytes\n"); printf(" --incremental Skip files unchanged since last transfer\n"); + printf(" --size-only Skip incremental files matching in size, ignoring mtime\n"); printf(" -I, --ignore-times Transfer files even when size and mtime match\n"); printf(" --delta Delta transfer for changed files (requires --incremental)\n"); printf(" -W, --whole-file Transfer changed files without delta processing\n"); diff --git a/src/server/receiver.c b/src/server/receiver.c index a84cbc3..63d7d10 100644 --- a/src/server/receiver.c +++ b/src/server/receiver.c @@ -61,7 +61,7 @@ static bool receiver_process_batch(Config* config, int file_descriptor) { struct stat st; bool has_old = file_stat_secure(full_path, &st); bool match = !config->ignore_times && has_old && (unsigned long long)st.st_size == check_size && - (long long)st.st_mtime == check_mtime; + (config->size_only || (long long)st.st_mtime == check_mtime); bool sent = send_status(file_descriptor, match ? STATUS_OK : STATUS_NEXT); free(full_path); free(check_path); diff --git a/src/server/server.c b/src/server/server.c index b1970af..7e0c2af 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -176,7 +176,7 @@ int receive_files(Config* config, int fd) { bool has_old = full_path && file_stat_secure(full_path, &st); bool match = !config->ignore_times && has_old && (unsigned long long)st.st_size == check_size && - (long long)st.st_mtime == check_mtime; + (config->size_only || (long long)st.st_mtime == check_mtime); bool sent = send_status(fd, match ? STATUS_OK : STATUS_NEXT); free(full_path); free(check_path); diff --git a/src/shared/config.c b/src/shared/config.c index 47f529a..5ca0b97 100644 --- a/src/shared/config.c +++ b/src/shared/config.c @@ -36,6 +36,7 @@ static void config_set_defaults(Config* config) { config->min_size = 0; config->use_incremental = false; config->ignore_times = false; + config->size_only = false; config->use_delta = false; config->whole_file = false; config->delta_block_size = DELTA_BLOCK_SIZE_DEFAULT; @@ -122,8 +123,8 @@ static bool validate_received_config(const Config* config) { valid_wire_bool(config->use_chunk_serialization) && valid_wire_bool(config->use_compression) && valid_wire_bool(config->use_metadata) && valid_wire_bool(config->use_sendfile) && valid_wire_bool(config->use_delete) && - valid_wire_bool(config->use_incremental) && valid_wire_bool(config->use_delta) && - valid_wire_bool(config->ignore_times) && valid_wire_bool(config->backup) && + valid_wire_bool(config->use_incremental) && valid_wire_bool(config->size_only) && + valid_wire_bool(config->ignore_times) && valid_wire_bool(config->use_delta) && valid_wire_bool(config->follow_symlinks) && valid_wire_bool(config->copy_links) && valid_wire_bool(config->safe_links) && valid_wire_bool(config->copy_unsafe_links) && valid_wire_bool(config->preserve_hard_links) && valid_wire_bool(config->preserve_acls) && @@ -236,7 +237,8 @@ static bool send_core_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) && - send_int(fd, c->ignore_times) && send_int(fd, c->use_delta && !c->whole_file) && + send_int(fd, c->size_only) && send_int(fd, c->ignore_times) && + 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_max_file_size, sizeof(unsigned long long)); } @@ -293,6 +295,8 @@ static bool receive_delta_fields(int fd, Config* c) { return false; if (!receive_wire_bool(fd, &c->use_incremental)) return false; + if (!receive_wire_bool(fd, &c->size_only)) + return false; if (!receive_wire_bool(fd, &c->ignore_times)) return false; if (!receive_wire_bool(fd, &c->use_delta)) diff --git a/src/shared/config.h b/src/shared/config.h index 541ca15..3b37d38 100644 --- a/src/shared/config.h +++ b/src/shared/config.h @@ -36,6 +36,7 @@ typedef struct Config { unsigned long long min_size; bool use_incremental; bool ignore_times; + bool size_only; bool use_delta; bool whole_file; uint32_t delta_block_size; diff --git a/src/shared/file_receive.c b/src/shared/file_receive.c index 6c44c55..4c900c2 100644 --- a/src/shared/file_receive.c +++ b/src/shared/file_receive.c @@ -387,7 +387,7 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) { match = (old_size == 0 || old_data) && old_checksum == check_checksum; free(old_data); old_data = NULL; - } else if (match) { + } else if (match && !config->size_only) { match = (long long)st.st_mtime == check_mtime; } diff --git a/tests/integration/test_features.py b/tests/integration/test_features.py index eeb287f..5ad99af 100644 --- a/tests/integration/test_features.py +++ b/tests/integration/test_features.py @@ -331,6 +331,26 @@ class TestIncremental: with open(received_file, "rb") as f: assert f.read() == b"hello world\n" + def test_size_only_skips_same_size_with_different_mtime(self, shared_server): + clean_dir(DEST_DIR) + result, _ = run_client(SOURCE_DIR, DEST_DIR, flags=["-M"], port=shared_server.port) + assert result.returncode == 0 + + received = get_dest_received_dir(DEST_DIR, SOURCE_DIR) + received_file = os.path.join(received, "small.txt") + with open(received_file, "wb") as f: + f.write(b"different!!\n") + os.utime(received_file, (time.time() - 3600, time.time() - 3600)) + + result, _ = run_client( + SOURCE_DIR, DEST_DIR, + flags=["-M", "--incremental", "--size-only"], + port=shared_server.port, + ) + assert result.returncode == 0, f"Size-only sync failed: {result.stderr[:200]}" + with open(received_file, "rb") as f: + assert f.read() == b"different!!\n" + def test_ignore_times_transfers_same_size_and_mtime(self, shared_server): clean_dir(DEST_DIR) result, _ = run_client(SOURCE_DIR, DEST_DIR, flags=["-M"], port=shared_server.port) diff --git a/tests/test_client_cli.c b/tests/test_client_cli.c index bcb0e94..23b5176 100644 --- a/tests/test_client_cli.c +++ b/tests/test_client_cli.c @@ -210,6 +210,20 @@ static void test_parse_args_valid_port() { config_delete(cfg); } +/* Test parse_args with --size-only. */ +static void test_parse_args_size_only() { + Config* cfg = config_create(); + char* argv[] = {"fastsync", "--size-only", "/src", "/dst"}; + int positional_args[2]; + int positional_count = 0; + + EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), 0); + EXPECT_TRUE(cfg->size_only); + EXPECT_EQ_INT(positional_count, 2); + + config_delete(cfg); +} + /* Test parse_args rejects port > 65535 */ static void test_parse_args_invalid_port() { Config* cfg = config_create(); @@ -568,6 +582,7 @@ void test_client_cli() { test_parse_args_help(); test_parse_args_version(); test_parse_args_valid_port(); + test_parse_args_size_only(); test_parse_args_invalid_port(); test_parse_args_non_numeric_port(); test_parse_args_invalid_server_port(); diff --git a/tests/test_config.c b/tests/test_config.c index 748e53a..2cea3d5 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -124,10 +124,10 @@ static void test_config_send_receive() { send_cfg->use_chunk_serialization = true; send_cfg->use_compression = true; send_cfg->use_metadata = true; - send_cfg->use_fsync = true; send_cfg->use_delta = true; send_cfg->whole_file = true; send_cfg->ignore_times = true; + send_cfg->size_only = true; send_cfg->compression_level = 5; send_cfg->chunk_size = 1024; send_cfg->eight_bit_output = true; @@ -161,13 +161,13 @@ static void test_config_send_receive() { ok = false; if (!recv_cfg->use_chunk_serialization) ok = false; - if (!recv_cfg->ignore_times) - ok = false; if (recv_cfg->compression_level != 5) ok = false; if (recv_cfg->chunk_size != 1024) ok = false; - if (!recv_cfg->use_fsync) + if (!recv_cfg->size_only) + ok = false; + if (!recv_cfg->ignore_times) ok = false; if (!recv_cfg->eight_bit_output) ok = false; @@ -200,11 +200,11 @@ static void test_config_send_receive() { } static void test_config_send_receive_version_mismatch() { - /* Create a config with a different protocol version */ + /* A peer using the previous wire format must be rejected. */ Config* cfg = config_create(); EXPECT_NOT_NULL(cfg); free(cfg->version); - cfg->version = str_dup("0.0"); + cfg->version = str_dup("2.2.0"); cfg->send_directory = str_dup("/src"); cfg->receive_root_directory = str_dup("/dst");