fix: clarify unsupported directory option diagnostics
CI / lint (pull_request) Successful in 11s
CI / sanitizers (address) (pull_request) Successful in 36s
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 1m15s
CI / valgrind (pull_request) Successful in 33s

This commit is contained in:
2026-09-03 22:32:09 +02:00
parent ce64fcd4b1
commit 9f23b23893
2 changed files with 27 additions and 8 deletions
+11 -7
View File
@@ -187,7 +187,8 @@ static const OptionEntry* find_table_option(const char* arg) {
return NULL;
}
static int apply_table_option(Config* config, const OptionEntry* entry, const char* value) {
static int apply_table_option(Config* config, const OptionEntry* entry, const char* option_name,
const char* value) {
void* field = (char*)config + entry->offset;
switch (entry->kind) {
case OPT_FLAG:
@@ -208,8 +209,8 @@ static int apply_table_option(Config* config, const OptionEntry* entry, const ch
}
case OPT_UNSUPPORTED:
log_message(LOG_LEVEL_ERROR,
"%s requires --dirs, which is not implemented; refusing to ignore option",
entry->name);
"%s: directory-only transfer is not implemented; refusing to ignore option",
option_name);
return -1;
}
return -1;
@@ -221,14 +222,17 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args,
for (int i = 1; i < argc; i++) {
const OptionEntry* entry = find_table_option(argv[i]);
if (entry) {
const char* option_name = argv[i];
const char* value = NULL;
if (entry->kind != OPT_FLAG) {
if (i + 1 >= argc) {
if (entry->kind != OPT_UNSUPPORTED && i + 1 >= argc) {
log_message(LOG_LEVEL_ERROR, "missing argument for %s", entry->name);
return -1;
}
if (apply_table_option(config, entry, argv[++i]) != 0)
return -1;
} else if (apply_table_option(config, entry, NULL) != 0) {
if (entry->kind != OPT_UNSUPPORTED)
value = argv[++i];
}
if (apply_table_option(config, entry, option_name, value) != 0) {
return -1;
}
continue;
+16 -1
View File
@@ -1,8 +1,10 @@
#include "test_client_cli.h"
#include "client_validation.h"
#include "config.h"
#include "log.h"
#include "test_utils.h"
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -260,7 +262,7 @@ static void test_parse_args_unknown_option() {
config_delete(cfg);
}
/* Directory aliases require the not-yet-implemented --dirs behavior. */
/* Directory aliases must report the unsupported directory-only behavior clearly. */
static void test_parse_args_rejects_dirs_aliases() {
static const char* const options[] = {"--dirs", "--old-dirs", "--old-d"};
@@ -269,8 +271,21 @@ static void test_parse_args_rejects_dirs_aliases() {
char* argv[] = {"fastsync", (char*)options[i], "/src", "/dst"};
int positional_args[2];
int positional_count = 0;
FILE* log_file = tmpfile();
char log_buffer[256] = {0};
EXPECT_NOT_NULL(log_file);
log_set_file(log_file);
EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), -1);
fflush(log_file);
rewind(log_file);
EXPECT_TRUE(fread(log_buffer, 1, sizeof(log_buffer) - 1, log_file) > 0);
EXPECT_TRUE(strstr(log_buffer, options[i]) != NULL);
EXPECT_TRUE(strstr(log_buffer, "directory-only transfer is not implemented") != NULL);
EXPECT_TRUE(strstr(log_buffer, "requires --dirs") == NULL);
log_set_file(NULL);
fclose(log_file);
config_delete(cfg);
}
}