Merge remote-tracking branch 'origin/feat/executability' into dev
This commit is contained in:
@@ -170,6 +170,26 @@ class TestArchiveMode:
|
||||
assert not mismatches, f"Mismatch: {mismatches}"
|
||||
|
||||
|
||||
class TestExecutability:
|
||||
def test_preserves_only_executable_bits(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "executability_source")
|
||||
dest = os.path.join(TEST_DATA_DIR, "executability_dest")
|
||||
clean_dir(source)
|
||||
clean_dir(dest)
|
||||
source_file = os.path.join(source, "tool.sh")
|
||||
with open(source_file, "w") as f:
|
||||
f.write("#!/bin/sh\necho test\n")
|
||||
os.chmod(source_file, 0o751)
|
||||
|
||||
result, _ = run_client(source, dest, flags=["-E"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"Executability sync failed: {result.stderr[:200]}"
|
||||
received_file = os.path.join(get_dest_received_dir(dest, source), "tool.sh")
|
||||
received_mode = os.stat(received_file).st_mode
|
||||
assert received_mode & 0o111 == 0o111
|
||||
assert received_mode & 0o600 == 0o600
|
||||
assert received_mode & 0o077 == 0o011
|
||||
|
||||
|
||||
class TestExclude:
|
||||
def test_exclude_single(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
|
||||
@@ -237,6 +237,19 @@ static void test_parse_args_ignore_existing() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_executability() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "-E", "/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->use_executability);
|
||||
EXPECT_TRUE(cfg->use_metadata);
|
||||
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
/* Test parse_args rejects port > 65535 */
|
||||
static void test_parse_args_invalid_port() {
|
||||
Config* cfg = config_create();
|
||||
@@ -657,6 +670,7 @@ void test_client_cli() {
|
||||
test_parse_args_valid_port();
|
||||
test_parse_args_size_only();
|
||||
test_parse_args_ignore_existing();
|
||||
test_parse_args_executability();
|
||||
test_parse_args_invalid_port();
|
||||
test_parse_args_non_numeric_port();
|
||||
test_parse_args_invalid_server_port();
|
||||
|
||||
@@ -124,6 +124,7 @@ 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_executability = true;
|
||||
send_cfg->use_delta = true;
|
||||
send_cfg->whole_file = true;
|
||||
send_cfg->ignore_times = true;
|
||||
@@ -168,6 +169,8 @@ static void test_config_send_receive() {
|
||||
ok = false;
|
||||
if (recv_cfg->chunk_size != 1024)
|
||||
ok = false;
|
||||
if (!recv_cfg->use_executability)
|
||||
ok = false;
|
||||
if (!recv_cfg->size_only)
|
||||
ok = false;
|
||||
if (!recv_cfg->ignore_times)
|
||||
|
||||
+1
-1
@@ -274,7 +274,7 @@ static void test_file_write_to_disk_with_fsync() {
|
||||
const char* path = "test_file_write_to_disk_fsync.txt";
|
||||
const char* content = "fsync file content";
|
||||
EXPECT_TRUE(
|
||||
file_to_disk_secure_with_fsync(path, content, strlen(content), false, false, NULL, true));
|
||||
file_to_disk_secure_with_fsync(path, content, strlen(content), false, false, NULL, false, true));
|
||||
struct stat st;
|
||||
EXPECT_EQ_INT(stat(path, &st), 0);
|
||||
EXPECT_EQ_INT((int)st.st_size, (int)strlen(content));
|
||||
|
||||
+32
-1
@@ -146,7 +146,7 @@ static void test_file_restore_metadata() {
|
||||
m.mtime_sec = 1234567890;
|
||||
m.mtime_nsec = 0;
|
||||
|
||||
file_restore_metadata(path, &m);
|
||||
file_restore_metadata(path, &m, false);
|
||||
|
||||
struct stat st;
|
||||
EXPECT_EQ_INT(stat(path, &st), 0);
|
||||
@@ -156,6 +156,35 @@ static void test_file_restore_metadata() {
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
static void test_file_restore_executability_only() {
|
||||
const char* path = "temp_exec_restore_test.txt";
|
||||
EXPECT_TRUE(file_write_to_disk(path, "x", 1, false, false));
|
||||
EXPECT_EQ_INT(chmod(path, 0644), 0);
|
||||
|
||||
FileMetadata m = {
|
||||
.mode = 0751, .uid = getuid(), .gid = getgid(), .mtime_sec = 0, .mtime_nsec = 0};
|
||||
file_restore_metadata(path, &m, true);
|
||||
|
||||
struct stat st;
|
||||
EXPECT_EQ_INT(stat(path, &st), 0);
|
||||
EXPECT_EQ_INT(st.st_mode & 0777, 0755);
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
static void test_directory_restore_executability_only() {
|
||||
const char* path = "temp_exec_restore_test_dir";
|
||||
EXPECT_EQ_INT(mkdir(path, 0700), 0);
|
||||
|
||||
FileMetadata m = {
|
||||
.mode = 0755, .uid = getuid(), .gid = getgid(), .mtime_sec = 0, .mtime_nsec = 0};
|
||||
file_restore_metadata(path, &m, true);
|
||||
|
||||
struct stat st;
|
||||
EXPECT_EQ_INT(stat(path, &st), 0);
|
||||
EXPECT_EQ_INT(st.st_mode & 0777, 0711);
|
||||
rmdir(path);
|
||||
}
|
||||
|
||||
void test_metadata() {
|
||||
test_metadata_to_from_buf_roundtrip();
|
||||
test_metadata_to_buf_null();
|
||||
@@ -165,4 +194,6 @@ void test_metadata() {
|
||||
test_metadata_rejects_invalid_values();
|
||||
test_metadata_mtime_window();
|
||||
test_file_restore_metadata();
|
||||
test_file_restore_executability_only();
|
||||
test_directory_restore_executability_only();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user