Add remove-source-files option
CI / lint (pull_request) Successful in 11s
CI / sanitizers (undefined) (pull_request) Successful in 37s
CI / sanitizers (address) (pull_request) Successful in 38s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m15s
CI / valgrind (pull_request) Successful in 33s
CI / lint (pull_request) Successful in 11s
CI / sanitizers (undefined) (pull_request) Successful in 37s
CI / sanitizers (address) (pull_request) Successful in 38s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 32s
CI / build-and-test (pull_request) Successful in 1m15s
CI / valgrind (pull_request) Successful in 33s
This commit is contained in:
@@ -36,6 +36,54 @@ class TestDryRun:
|
||||
assert "Dry run:" in result.stdout, f"No dry run output: {result.stdout[:200]}"
|
||||
|
||||
|
||||
class TestRemoveSourceFiles:
|
||||
def test_removes_only_transferred_regular_files(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "remove_source")
|
||||
dest = os.path.join(TEST_DATA_DIR, "remove_dest")
|
||||
clean_dir(source)
|
||||
clean_dir(dest)
|
||||
with open(os.path.join(source, "one.txt"), "wb") as f:
|
||||
f.write(b"one")
|
||||
with open(os.path.join(source, "two.txt"), "wb") as f:
|
||||
f.write(b"two")
|
||||
os.makedirs(os.path.join(source, "directory"))
|
||||
os.symlink("one.txt", os.path.join(source, "link.txt"))
|
||||
|
||||
result, _ = run_client(source, dest, flags=["--remove-source-files", "-m"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, f"Remove-source sync failed: {result.stderr[:200]}"
|
||||
assert not os.path.exists(os.path.join(source, "one.txt"))
|
||||
assert not os.path.exists(os.path.join(source, "two.txt"))
|
||||
assert os.path.isdir(os.path.join(source, "directory"))
|
||||
assert os.path.islink(os.path.join(source, "link.txt"))
|
||||
|
||||
def test_dry_run_preserves_source_files(self):
|
||||
source = os.path.join(TEST_DATA_DIR, "remove_dry_source")
|
||||
dest = os.path.join(TEST_DATA_DIR, "remove_dry_dest")
|
||||
clean_dir(source)
|
||||
clean_dir(dest)
|
||||
source_file = os.path.join(source, "file.txt")
|
||||
with open(source_file, "wb") as f:
|
||||
f.write(b"keep")
|
||||
|
||||
result, _ = run_client(source, dest, flags=["--remove-source-files", "--dry-run"])
|
||||
assert result.returncode == 0
|
||||
assert os.path.isfile(source_file)
|
||||
|
||||
def test_failed_connection_preserves_source_files(self):
|
||||
source = os.path.join(TEST_DATA_DIR, "remove_failed_source")
|
||||
dest = os.path.join(TEST_DATA_DIR, "remove_failed_dest")
|
||||
clean_dir(source)
|
||||
clean_dir(dest)
|
||||
source_file = os.path.join(source, "file.txt")
|
||||
with open(source_file, "wb") as f:
|
||||
f.write(b"keep after failure")
|
||||
|
||||
result, _ = run_client(source, dest, flags=["--remove-source-files"], port=1)
|
||||
assert result.returncode != 0
|
||||
assert os.path.isfile(source_file)
|
||||
|
||||
|
||||
class TestArchiveMode:
|
||||
def test_archive_mode(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
|
||||
@@ -107,6 +107,27 @@ static void test_cli_dry_run() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_cli_remove_source_files() {
|
||||
Config* cfg = config_create();
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
EXPECT_FALSE(cfg->remove_source_files);
|
||||
cfg->remove_source_files = true;
|
||||
EXPECT_TRUE(cfg->remove_source_files);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_remove_source_files() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--remove-source-files", "/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->remove_source_files);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
/* Test that --delete sets use_delete */
|
||||
static void test_cli_delete_flag() {
|
||||
Config* cfg = config_create();
|
||||
@@ -347,6 +368,8 @@ void test_client_cli() {
|
||||
test_cli_help();
|
||||
test_cli_archive_flags();
|
||||
test_cli_dry_run();
|
||||
test_cli_remove_source_files();
|
||||
test_parse_args_remove_source_files();
|
||||
test_cli_delete_flag();
|
||||
test_cli_exclude_patterns();
|
||||
test_parse_args_help();
|
||||
|
||||
Reference in New Issue
Block a user