From 0d7d5dacb3bff59d0f2135e2ab71dbd755e3431a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 11 May 2022 21:49:04 -0500 Subject: [PATCH] Bugfix: The fake program should not require the data directory when explicit fakefile or settings files are specified. Set or reset the validate_parameter_directories check as appropriate when calling 'clean' or 'skeleton' operations. Make the parameters_required check contingent on the presence of the parameters --fakefile and --settings. When these are specified, do not even bother checking for the data directory at all. --- level_3/fake/c/fake.c | 12 ++++++------ level_3/fake/c/private-fake.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index 7a7f6cb..bc37e60 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -306,13 +306,10 @@ extern "C" { } } else if (data.operation == fake_operation_clean_e) { - if (validate_parameter_directories) { - validate_parameter_directories = F_false; - } + status = fake_clean_operate(&data); - if (F_status_is_error_not(status)) { - status = fake_clean_operate(&data); - } + // Reset in case next operation needs files. + validate_parameter_directories = F_true; } else if (data.operation == fake_operation_make_e) { if (validate_parameter_directories) { @@ -327,6 +324,9 @@ extern "C" { } else if (data.operation == fake_operation_skeleton_e) { status = fake_skeleton_operate(&data); + + // Skeleton is supposed to guarantee these. + validate_parameter_directories = F_false; } if (status == F_child) break; diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 7d7809f..c8232bd 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -533,18 +533,42 @@ extern "C" { data->path_work, }; - const bool parameters_required[] = { + uint8_t parameters_required[] = { F_false, F_true, F_false, }; + // Check only expected operations (fake_operation_clean_e and fake_operation_skeleton_e should not call this function). + if (data->operation == fake_operation_make_e) { + + // If a custom --data or a custom --fakefile parameter is passed and uses an absolute or relative to current path, then do not check. + if (data->main->parameters.array[fake_parameter_fakefile_e].result == f_console_result_additional_e) { + const f_array_length_t index = data->main->parameters.array[fake_parameter_fakefile_e].values.array[data->main->parameters.array[fake_parameter_fakefile_e].values.used - 1]; + + if (f_path_is_absolute(data->main->parameters.arguments.array[index]) == F_true || f_path_is_relative_current(data->main->parameters.arguments.array[index]) == F_true) { + parameters_required[1] = F_none; + } + } + } + else if (data->operation == fake_operation_build_e) { + + // If a custom --data or a custom --settings parameter is passed and uses an absolute or relative to current path, then do not check. + if (data->main->parameters.array[fake_parameter_settings_e].result == f_console_result_additional_e) { + const f_array_length_t index = data->main->parameters.array[fake_parameter_fakefile_e].values.array[data->main->parameters.array[fake_parameter_fakefile_e].values.used - 1]; + + if (f_path_is_absolute(data->main->parameters.arguments.array[index]) == F_true || f_path_is_relative_current(data->main->parameters.arguments.array[index]) == F_true) { + parameters_required[1] = F_none; + } + } + } + struct stat directory_stat; f_status_t status = F_none; for (uint8_t i = 0; i < 3; ++i) { - if (parameters_value[i].used) { + if (parameters_required[i] != F_none && parameters_value[i].used) { memset(&directory_stat, 0, sizeof(struct stat)); status = f_file_stat(parameters_value[i], F_true, &directory_stat); @@ -559,7 +583,7 @@ extern "C" { } } } - else if (parameters_required[i]) { + else if (parameters_required[i] == F_true) { flockfile(data->main->error.to.stream); fl_print_format("%r%[%QNo valid path for the (required) directory parameter '%]", data->main->error.to.stream, f_string_eol_s, data->main->error.context, data->main->error.prefix, data->main->error.context); -- 1.8.3.1