From 4bd0c07f0da46be1a7773c1ee10cd60841135fab Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 27 Apr 2025 17:18:00 -0500 Subject: [PATCH] Regression: Fix the preserve and offset calculation in Featureless Make. This addresses the problems observed in commit 3befe37125e426d452a1b9b9a1fab97ab221c7f1. I never got the time to investigate this before I made my end of day commit. This now addresses the observed problems. The offset application logic is accidentally reversed. This is now corrected. The new logic does not require the buffer because the directory is being created later on in the process. Using the `f_string_append_nulless()` to easily copy the source path with the offset onto the destination path. Update the documentation comments to better communicate this behavior. --- level_3/fake/c/main/build.c | 22 ++++++++-------------- level_3/fake/c/main/build.h | 11 ++++++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/level_3/fake/c/main/build.c b/level_3/fake/c/main/build.c index f51813a..4956ec2 100644 --- a/level_3/fake/c/main/build.c +++ b/level_3/fake/c/main/build.c @@ -173,7 +173,6 @@ extern "C" { fake_main_t * const main = data->main; - f_string_static_t buffer = f_string_static_t_initialize; f_status_t failed = F_okay; fake_local_t local = macro_fake_local_t_initialize_1(main, &main->cache_map, &failed); uint8_t func = 0; @@ -244,20 +243,13 @@ extern "C" { } if (F_status_is_error_not(main->setting.state.status)) { - if (preserve) { - func = 3; - main->setting.state.status = f_file_name_base(files.array[i], &main->cache_map.value); + if (preserve && offset < main->cache_map.key.used) { + func = 9; + main->setting.state.status = f_string_append_nulless(main->cache_map.key.string + offset, main->cache_map.key.used - offset, &main->cache_map.value); } else { - if (offset) { - buffer.string = files.array[i].string + offset; - buffer.used = files.array[i].used - offset; - - main->setting.state.status = f_string_dynamic_append_nulless(buffer, &main->cache_map.value); - } - else { - main->setting.state.status = f_string_dynamic_append_nulless(files.array[i], &main->cache_map.value); - } + func = 3; + main->setting.state.status = f_file_name_base(files.array[i], &main->cache_map.value); } } @@ -343,7 +335,9 @@ extern "C" { ? macro_fake_f(f_file_name_directory) : func == 7 ? macro_fake_f(fl_directory_create) - : macro_fake_f(f_file_copy), + : func == 8 + ? macro_fake_f(f_file_copy) + : macro_fake_f(f_string_append_nulless), f_file_operation_copy_s, main->cache_map.key, main->cache_map.value, diff --git a/level_3/fake/c/main/build.h b/level_3/fake/c/main/build.h index 04702da..8da450b 100644 --- a/level_3/fake/c/main/build.h +++ b/level_3/fake/c/main/build.h @@ -87,14 +87,15 @@ extern "C" { * @param file_stage * The specific stage file path. * @param preserve - * Set to F_true to preserve the path. - * Set to F_False to only use the base name when copying. + * Set to F_true to preserve the path and offset is used with the source path to construct the destination path. + * Set to F_false to only use the file name as the destination. * @param offset - * When preserve is F_true, this represents the amount of characters at the front of each path to ignore. + * When preserve is F_true, this offset represents the amount of characters at the front of each path to ignore. * Everything after the offset is preserved, and directories are created if necessary. + * The offset must be based on the source string. * - * Example: 'sources/c/level_0/fss.h' with a preseve of 10, would result in the path of 'level_0/fss.h' being preserved. - * Whereas a preseve is F_false, then the path used would instead be 'fss.h' (the 'sources/c/level_0/' directories are not preserved). + * Example: 'sources/c/level_0/fss.h' a preserve F_true and an offset of 10 would result in the path of 'level_0/fss.h' being preserved. + * Whereas when preseve is F_false, then the path used would instead be 'fss.h' (the 'sources/c/level_0/' directories are not preserved). * * @see f_directory_is() * @see f_file_copy() -- 1.8.3.1