Merge remote-tracking branch 'origin/feat/rsync-info' into dev
This commit is contained in:
+79
-12
@@ -178,6 +178,52 @@ static int parse_debug_flags(const char* value, Config* config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_info_flags(const char* value, Config* config) {
|
||||
if (!value || value[0] == '\0' || value[0] == ',' || value[strlen(value) - 1] == ',' ||
|
||||
strstr(value, ",,")) {
|
||||
log_message(LOG_LEVEL_ERROR, "--info requires at least one flag");
|
||||
return -1;
|
||||
}
|
||||
char* flags = str_dup(value);
|
||||
if (!flags) {
|
||||
log_message(LOG_LEVEL_ERROR, "memory allocation failed for --info");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t parsed = (uint32_t)config->info_level;
|
||||
char* saveptr = NULL;
|
||||
for (char* token = strtok_r(flags, ",", &saveptr); token != NULL;
|
||||
token = strtok_r(NULL, ",", &saveptr)) {
|
||||
uint32_t flag = 0;
|
||||
if (strcmp(token, "all") == 0) {
|
||||
parsed = LOG_INFO_ALL;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(token, "none") == 0) {
|
||||
parsed = 0;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(token, "copy") == 0)
|
||||
flag = LOG_INFO_COPY;
|
||||
else if (strcmp(token, "misc") == 0)
|
||||
flag = LOG_INFO_MISC;
|
||||
else if (strcmp(token, "skip") == 0)
|
||||
flag = LOG_INFO_SKIP;
|
||||
else if (strcmp(token, "stats") == 0)
|
||||
flag = LOG_INFO_STATS;
|
||||
else {
|
||||
log_message(LOG_LEVEL_ERROR, "unsupported --info flag: %s", token);
|
||||
free(flags);
|
||||
return -1;
|
||||
}
|
||||
parsed |= flag;
|
||||
}
|
||||
free(flags);
|
||||
config->info_level = (int)parsed;
|
||||
set_log_info_flags(parsed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse a string as an unsigned long long. Returns 0 on success, -1 on error. */
|
||||
static int parse_ull_arg(const char* val, unsigned long long* out, const char* optname) {
|
||||
char* end;
|
||||
@@ -418,8 +464,22 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
||||
int* positional_count) {
|
||||
bool verbose = false;
|
||||
protocol_set_8_bit_output(config->eight_bit_output);
|
||||
|
||||
/* Apply output controls before processing other options so their order is irrelevant. */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
const char* modify_window_prefix = "--modify-window=";
|
||||
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
|
||||
set_log_level(LOG_LEVEL_DEBUG);
|
||||
} else if (strncmp(argv[i], "--info=", 7) == 0) {
|
||||
if (parse_info_flags(argv[i] + 7, config) != 0)
|
||||
return -1;
|
||||
} else if (strcmp(argv[i], "--info") == 0) {
|
||||
if (i + 1 >= argc || parse_info_flags(argv[++i], config) != 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
const char* modify_window_prefix = "--modify-window=";
|
||||
if (strncmp(argv[i], modify_window_prefix, strlen(modify_window_prefix)) == 0) {
|
||||
if (set_nonneg_int_option(&config->modify_window, argv[i] + strlen(modify_window_prefix),
|
||||
"--modify-window") != 0)
|
||||
@@ -518,7 +578,7 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
!config->compress_choice || strcmp(config->compress_choice, "zstd") == 0;
|
||||
config->use_multithreading = true;
|
||||
config->use_metadata = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled archive mode (-c -m -M)");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled archive mode (-c -m -M)");
|
||||
} else if (opt_is(argv[i], "-p", NULL) && i + 1 < argc) {
|
||||
if (set_positive_int_option(&config->ssh_port, argv[++i], "-p") != 0)
|
||||
return -1;
|
||||
@@ -553,7 +613,7 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
} else if (opt_is(argv[i], "-c", "-z")) {
|
||||
config->use_compression =
|
||||
!config->compress_choice || strcmp(config->compress_choice, "zstd") == 0;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled Compression");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled Compression");
|
||||
if (i + 1 < argc) {
|
||||
char* end_ptr;
|
||||
long level = strtol(argv[i + 1], &end_ptr, 10);
|
||||
@@ -563,26 +623,26 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
return -1;
|
||||
}
|
||||
config->compression_level = (int)level;
|
||||
log_message(LOG_LEVEL_INFO, "Set Compression level to %ld", level);
|
||||
log_info_message(LOG_INFO_MISC, "Set Compression level to %ld", level);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else if (opt_is(argv[i], "-M", "--preserve")) {
|
||||
config->use_metadata = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled metadata preservation");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled metadata preservation");
|
||||
} else if (opt_is(argv[i], "-E", "--executability")) {
|
||||
config->use_metadata = true;
|
||||
config->use_executability = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled executable permission preservation");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled executable permission preservation");
|
||||
} else if (opt_is(argv[i], "-f", "--sendfile")) {
|
||||
config->use_sendfile = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled sendfile");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled sendfile");
|
||||
} else if (opt_is(argv[i], "-m", NULL)) {
|
||||
config->use_multithreading = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled Multithreading");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled Multithreading");
|
||||
} else if (opt_is(argv[i], "-s", NULL)) {
|
||||
config->use_chunk_serialization = true;
|
||||
log_message(LOG_LEVEL_INFO, "Enabled Chunk Serialization");
|
||||
log_info_message(LOG_INFO_MISC, "Enabled Chunk Serialization");
|
||||
} else if (opt_is(argv[i], "--server-port", NULL) && i + 1 < argc) {
|
||||
if (!parse_positive_int(argv[++i], &config->server_port)) {
|
||||
char* escaped = output_escape(argv[i], false);
|
||||
@@ -608,7 +668,7 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
return -1;
|
||||
}
|
||||
io_set_bwlimit(kbps * 1024);
|
||||
log_message(LOG_LEVEL_INFO, "Set bandwidth limit to %llu KB/s", kbps);
|
||||
log_info_message(LOG_INFO_MISC, "Set bandwidth limit to %llu KB/s", kbps);
|
||||
} else if (opt_is(argv[i], "--chunk-size", NULL) && i + 1 < argc) {
|
||||
unsigned long long val;
|
||||
if (parse_ull_arg(argv[++i], &val, "--chunk-size") != 0)
|
||||
@@ -650,6 +710,7 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
return -1;
|
||||
} else if (opt_is(argv[i], "-v", "--verbose")) {
|
||||
verbose = true;
|
||||
set_log_level(LOG_LEVEL_DEBUG);
|
||||
} else if (opt_is(argv[i], "-q", "--quiet")) {
|
||||
config->quiet = true;
|
||||
} else if (strncmp(argv[i], "--debug=", 8) == 0) {
|
||||
@@ -662,6 +723,12 @@ const char* modify_window_prefix = "--modify-window=";
|
||||
int debug_ret = parse_debug_flags(argv[++i], config);
|
||||
if (debug_ret != 0)
|
||||
return debug_ret;
|
||||
} else if (strncmp(argv[i], "--info=", 7) == 0) {
|
||||
if (parse_info_flags(argv[i] + 7, config) != 0)
|
||||
return -1;
|
||||
} else if (opt_is(argv[i], "--info", NULL)) {
|
||||
if (i + 1 >= argc || parse_info_flags(argv[++i], config) != 0)
|
||||
return -1;
|
||||
} else if (opt_is(argv[i], "-T", NULL) && i + 1 < argc) {
|
||||
if (set_positive_int_option(&config->timeout, argv[++i], "-T") != 0)
|
||||
return -1;
|
||||
@@ -806,11 +873,11 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
/* Enable implicit flags */
|
||||
if (config->use_incremental && !config->use_metadata) {
|
||||
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --incremental");
|
||||
log_info_message(LOG_INFO_MISC, "Enabling metadata preservation for --incremental");
|
||||
config->use_metadata = true;
|
||||
}
|
||||
if (config->use_delta && !config->use_metadata) {
|
||||
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --delta");
|
||||
log_info_message(LOG_INFO_MISC, "Enabling metadata preservation for --delta");
|
||||
config->use_metadata = true;
|
||||
}
|
||||
/* Initialize TLS if needed */
|
||||
|
||||
Reference in New Issue
Block a user