feat: add rsync-compatible --chmod #244
+2
-2
@@ -62,12 +62,12 @@ bool chmod_apply(mode_t mode, const char* spec, mode_t* result) {
|
||||
for (size_t i = 0; i < length && numeric; i++)
|
||||
numeric = spec[i] >= '0' && spec[i] <= '7';
|
||||
if (numeric) {
|
||||
if (length < 3 || (length == 4 && spec[0] != '0'))
|
||||
if (length == 0 || length > 4)
|
||||
return false;
|
||||
mode_t parsed = 0;
|
||||
for (size_t i = 0; i < length; i++)
|
||||
parsed = (mode_t)((parsed << 3) | (spec[i] - '0'));
|
||||
*result = (*result & ~07777) | parsed;
|
||||
*result = parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,17 @@ static void test_parse_args_chmod() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_numeric_chmod() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--chmod", "7777", "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 5, argv, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_STR(cfg->chmod_spec, "7777");
|
||||
EXPECT_TRUE(cfg->use_metadata);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_rejects_invalid_chmod() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--chmod=a+X", "/src", "/dst"};
|
||||
@@ -377,6 +388,7 @@ void test_client_cli() {
|
||||
test_parse_args_version();
|
||||
test_parse_args_valid_port();
|
||||
test_parse_args_chmod();
|
||||
test_parse_args_numeric_chmod();
|
||||
test_parse_args_rejects_invalid_chmod();
|
||||
test_parse_args_invalid_port();
|
||||
test_parse_args_non_numeric_port();
|
||||
|
||||
@@ -151,8 +151,17 @@ static void test_chmod_changes() {
|
||||
EXPECT_EQ_INT(result, 0644);
|
||||
EXPECT_TRUE(chmod_apply(0644, "a+x", &result));
|
||||
EXPECT_EQ_INT(result, 0755);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "0000", &result));
|
||||
EXPECT_EQ_INT(result, 0000);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "7777", &result));
|
||||
EXPECT_EQ_INT(result, 07777);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "755", &result));
|
||||
EXPECT_EQ_INT(result, 0755);
|
||||
EXPECT_FALSE(chmod_apply(0777, "888", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "10000", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "a+X", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "a+r,", &result));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user