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
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:
+11
-7
@@ -187,7 +187,8 @@ static const OptionEntry* find_table_option(const char* arg) {
|
|||||||
return NULL;
|
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;
|
void* field = (char*)config + entry->offset;
|
||||||
switch (entry->kind) {
|
switch (entry->kind) {
|
||||||
case OPT_FLAG:
|
case OPT_FLAG:
|
||||||
@@ -208,8 +209,8 @@ static int apply_table_option(Config* config, const OptionEntry* entry, const ch
|
|||||||
}
|
}
|
||||||
case OPT_UNSUPPORTED:
|
case OPT_UNSUPPORTED:
|
||||||
log_message(LOG_LEVEL_ERROR,
|
log_message(LOG_LEVEL_ERROR,
|
||||||
"%s requires --dirs, which is not implemented; refusing to ignore option",
|
"%s: directory-only transfer is not implemented; refusing to ignore option",
|
||||||
entry->name);
|
option_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
const OptionEntry* entry = find_table_option(argv[i]);
|
const OptionEntry* entry = find_table_option(argv[i]);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
|
const char* option_name = argv[i];
|
||||||
|
const char* value = NULL;
|
||||||
if (entry->kind != OPT_FLAG) {
|
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);
|
log_message(LOG_LEVEL_ERROR, "missing argument for %s", entry->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (apply_table_option(config, entry, argv[++i]) != 0)
|
if (entry->kind != OPT_UNSUPPORTED)
|
||||||
return -1;
|
value = argv[++i];
|
||||||
} else if (apply_table_option(config, entry, NULL) != 0) {
|
}
|
||||||
|
if (apply_table_option(config, entry, option_name, value) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+16
-1
@@ -1,8 +1,10 @@
|
|||||||
#include "test_client_cli.h"
|
#include "test_client_cli.h"
|
||||||
#include "client_validation.h"
|
#include "client_validation.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -260,7 +262,7 @@ static void test_parse_args_unknown_option() {
|
|||||||
config_delete(cfg);
|
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 void test_parse_args_rejects_dirs_aliases() {
|
||||||
static const char* const options[] = {"--dirs", "--old-dirs", "--old-d"};
|
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"};
|
char* argv[] = {"fastsync", (char*)options[i], "/src", "/dst"};
|
||||||
int positional_args[2];
|
int positional_args[2];
|
||||||
int positional_count = 0;
|
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);
|
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);
|
config_delete(cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user