Add rsync-compatible ignore-existing option
CI / lint (pull_request) Successful in 12s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 36s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 33s
CI / lint (pull_request) Successful in 12s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 36s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 33s
This commit is contained in:
@@ -214,6 +214,29 @@ class TestIncremental:
|
||||
assert f.read() == b"hello world\n"
|
||||
|
||||
|
||||
class TestIgnoreExisting:
|
||||
def test_ignore_existing_preserves_existing_and_transfers_new(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR, port=shared_server.port)
|
||||
assert result.returncode == 0
|
||||
|
||||
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
|
||||
existing_file = os.path.join(received, "small.txt")
|
||||
with open(existing_file, "wb") as f:
|
||||
f.write(b"destination content\n")
|
||||
new_source = os.path.join(SOURCE_DIR, "new.txt")
|
||||
with open(new_source, "wb") as f:
|
||||
f.write(b"new file\n")
|
||||
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR,
|
||||
flags=["--ignore-existing"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"Sync failed: {(result.stderr or result.stdout)[:200]}"
|
||||
with open(existing_file, "rb") as f:
|
||||
assert f.read() == b"destination content\n"
|
||||
with open(os.path.join(received, "new.txt"), "rb") as f:
|
||||
assert f.read() == b"new file\n"
|
||||
|
||||
|
||||
class TestDelete:
|
||||
def test_delete_removes_extra_files(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
|
||||
@@ -181,6 +181,19 @@ static void test_parse_args_valid_port() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_ignore_existing() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--ignore-existing", "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
|
||||
int ret = parse_args(cfg, 4, argv, positional_args, &positional_count);
|
||||
EXPECT_EQ_INT(ret, 0);
|
||||
EXPECT_TRUE(cfg->ignore_existing);
|
||||
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
/* Test parse_args rejects port > 65535 */
|
||||
static void test_parse_args_invalid_port() {
|
||||
Config* cfg = config_create();
|
||||
@@ -352,6 +365,7 @@ void test_client_cli() {
|
||||
test_parse_args_help();
|
||||
test_parse_args_version();
|
||||
test_parse_args_valid_port();
|
||||
test_parse_args_ignore_existing();
|
||||
test_parse_args_invalid_port();
|
||||
test_parse_args_non_numeric_port();
|
||||
test_parse_args_invalid_server_port();
|
||||
|
||||
@@ -126,6 +126,7 @@ static void test_config_send_receive() {
|
||||
send_cfg->use_metadata = true;
|
||||
send_cfg->compression_level = 5;
|
||||
send_cfg->chunk_size = 1024;
|
||||
send_cfg->ignore_existing = true;
|
||||
|
||||
/* Use socketpair for bidirectional communication */
|
||||
int p[2];
|
||||
@@ -160,6 +161,8 @@ static void test_config_send_receive() {
|
||||
ok = false;
|
||||
if (recv_cfg->chunk_size != 1024)
|
||||
ok = false;
|
||||
if (!recv_cfg->ignore_existing)
|
||||
ok = false;
|
||||
}
|
||||
config_delete(recv_cfg);
|
||||
close(p[0]);
|
||||
|
||||
@@ -88,6 +88,38 @@ static void test_file_save_to_disk() {
|
||||
rmdir("test_save_tmp");
|
||||
}
|
||||
|
||||
static void test_file_save_to_disk_ignore_existing() {
|
||||
const char* path = "test_ignore_existing_tmp/existing.txt";
|
||||
EXPECT_TRUE(file_write_to_disk(path, "old", 3, false, false));
|
||||
|
||||
File* file = file_create("existing.txt");
|
||||
EXPECT_NOT_NULL(file);
|
||||
file->data->data = malloc(3);
|
||||
EXPECT_NOT_NULL(file->data->data);
|
||||
memcpy(file->data->data, "new", 3);
|
||||
file->data->size = 3;
|
||||
|
||||
Config* config = config_create();
|
||||
EXPECT_NOT_NULL(config);
|
||||
config->ignore_existing = true;
|
||||
EXPECT_TRUE(file_save_to_disk("test_ignore_existing_tmp", file, config));
|
||||
|
||||
FILE* stream = fopen(path, "rb");
|
||||
char content[4] = {0};
|
||||
EXPECT_NOT_NULL(stream);
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
if (stream) {
|
||||
EXPECT_EQ_INT((int)fread(content, 1, 3, stream), 3);
|
||||
fclose(stream);
|
||||
}
|
||||
EXPECT_EQ_STR(content, "old");
|
||||
|
||||
file_destroy(file);
|
||||
config_delete(config);
|
||||
unlink(path);
|
||||
rmdir("test_ignore_existing_tmp");
|
||||
}
|
||||
|
||||
static void test_file_write_to_disk_basic() {
|
||||
const char* content = "Basic file_write_to_disk test";
|
||||
EXPECT_TRUE(file_write_to_disk("test_file_write_to_disk_basic.txt", content, strlen(content),
|
||||
@@ -458,6 +490,7 @@ void test_file() {
|
||||
test_file_load_data();
|
||||
test_file_load_data_missing_file();
|
||||
test_file_save_to_disk();
|
||||
test_file_save_to_disk_ignore_existing();
|
||||
test_file_write_to_disk_basic();
|
||||
test_file_write_to_disk_creates_dirs();
|
||||
test_file_write_to_disk_does_not_follow_symlink();
|
||||
|
||||
Reference in New Issue
Block a user