From 6c3d8a13f68a82903dd0c978f90dded0bc8fc33c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 16 Jun 2025 22:48:44 -0500 Subject: [PATCH] Bugfix: File not found errors with f_file_access(). This is happening because the symbolic link is being followed. Avoid this behavior by switching to using f_file_access_at(). Set the directory to the current working directory, which happens to be `-100`. I need to revisit this once I decided on how I am going to handle the CWD of `-100` for the FLL library as a whole. Ignore file not found errors on access checks. If the file does not exist, then do not care if the access check for a non-existent file fails. --- .../program/kevux/tools/remove/main/common/print.c | 2 +- .../program/kevux/tools/remove/main/common/print.h | 2 +- .../c/program/kevux/tools/remove/main/preprocess.c | 46 ++++++++++++++++------ .../c/program/kevux/tools/remove/main/preprocess.h | 8 +++- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/sources/c/program/kevux/tools/remove/main/common/print.c b/sources/c/program/kevux/tools/remove/main/common/print.c index 2cf7e40..c8e3ed1 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.c +++ b/sources/c/program/kevux/tools/remove/main/common/print.c @@ -10,7 +10,7 @@ extern "C" { "f_console_parameter_process", "f_directory_empty", "f_directory_remove", - "f_file_access", + "f_file_access_at", "f_file_exists", "f_file_link_read", "f_file_mode_from_string", diff --git a/sources/c/program/kevux/tools/remove/main/common/print.h b/sources/c/program/kevux/tools/remove/main/common/print.h index 27e5037..a16b68c 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.h +++ b/sources/c/program/kevux/tools/remove/main/common/print.h @@ -43,7 +43,7 @@ extern "C" { kt_remove_f_f_console_parameter_process_e, kt_remove_f_f_directory_empty_e, kt_remove_f_f_directory_remove_e, - kt_remove_f_f_file_access_e, + kt_remove_f_f_file_access_at_e, kt_remove_f_f_file_exists_e, kt_remove_f_f_file_link_read_e, kt_remove_f_f_file_mode_from_string_e, diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index b56b525..0570980 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -114,7 +114,14 @@ extern "C" { } } - status = kt_remove_preprocess_file_access(main, path, flag_operate); + status = kt_remove_preprocess_file_access( + main, + path, + flag_operate, + *flag_operate & kt_remove_flag_operate_follow_d + ? AT_EACCESS + : AT_EACCESS | AT_SYMLINK_NOFOLLOW + ); if (F_status_is_error(status)) { *flag_operate |= kt_remove_flag_operate_remove_fail_d; @@ -402,7 +409,7 @@ extern "C" { #endif // _di_kt_remove_preprocess_file_ #ifndef _di_kt_remove_preprocess_file_access_ - f_status_t kt_remove_preprocess_file_access(kt_remove_main_t * const main, const f_string_static_t path, uint64_t * const flag_operate) { + f_status_t kt_remove_preprocess_file_access(kt_remove_main_t * const main, const f_string_static_t path, uint64_t * const flag_operate, const int access_flags) { if (!main || !flag_operate) { kt_remove_print_error_file_status(&main->program.error, macro_kt_remove_f(kt_remove_preprocess_file_access), path, f_file_operation_process_s, fll_error_file_type_path_e, F_status_set_error(F_parameter)); @@ -412,14 +419,23 @@ extern "C" { if (!path.used) return F_data_not; - f_status_t status = f_file_access(path, F_file_access_mode_read_d); + // -100 is the AT_CWD, @todo update FLL project and then this to provide a define for this. + const f_file_t cwd = macro_f_file_t_initialize_id(-100); + + f_status_t status = f_file_access_at(cwd, path, F_file_access_mode_read_d, access_flags); + + // Ignore file not found errors. + if (F_status_set_fine(status) == F_file_found_not) status = F_okay; if (F_status_is_error_not(status)) { if (status == F_false) { *flag_operate |= kt_remove_flag_operate_unable_read_d; } - status = f_file_access(path, F_file_access_mode_write_d); + status = f_file_access_at(cwd, path, F_file_access_mode_write_d, access_flags); + + // Ignore file not found errors. + if (F_status_set_fine(status) == F_file_found_not) status = F_okay; } if (F_status_is_error_not(status)) { @@ -427,27 +443,31 @@ extern "C" { *flag_operate |= kt_remove_flag_operate_unable_write_d; } - status = f_file_access(path, F_file_access_mode_execute_d); + status = f_file_access_at(cwd, path, F_file_access_mode_execute_d, access_flags); + + // Ignore file not found errors. + if (F_status_set_fine(status) == F_file_found_not) status = F_okay; } if (F_status_is_error_not(status)) { if (status == F_false) { *flag_operate |= kt_remove_flag_operate_unable_execute_d; } + } - if ((*flag_operate) & kt_remove_flag_operate_unable_rwx_d) { - kt_remove_print_simulate_operate_file_access(&main->program.output, *flag_operate, path); - } - - status = F_okay; + if ((*flag_operate) & kt_remove_flag_operate_unable_rwx_d) { + kt_remove_print_simulate_operate_file_access(&main->program.output, *flag_operate, path); } - else { + + if (F_status_is_error(status)) { status = F_status_set_error(F_parameter); - kt_remove_print_error_file_status(&main->program.error, macro_kt_remove_f(f_file_access), path, f_file_operation_access_s, fll_error_file_type_path_e, status); + kt_remove_print_error_file_status(&main->program.error, macro_kt_remove_f(f_file_access_at), path, f_file_operation_access_s, fll_error_file_type_path_e, status); + + return status; } - return status; + return F_okay; } #endif // _di_kt_remove_preprocess_file_access_ diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.h b/sources/c/program/kevux/tools/remove/main/preprocess.h index 6701818..e5096d4 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.h +++ b/sources/c/program/kevux/tools/remove/main/preprocess.h @@ -77,6 +77,8 @@ extern "C" { * The operate file specific flags from kt_remove_flag_operate_*_e. * * Must not be NULL. + * @param access_flags + * The access flags to use, such as AT_SYMLINK_NOFOLLOW. * * @return * F_okay on success. @@ -84,9 +86,13 @@ extern "C" { * * F_no (with error bit) on failure (not returned when simulating). * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_file_access_at(). + * + * @see f_file_access_at() */ #ifndef _di_kt_remove_preprocess_file_access_ - extern f_status_t kt_remove_preprocess_file_access(kt_remove_main_t * const main, const f_string_static_t path, uint64_t * const flag_operate); + extern f_status_t kt_remove_preprocess_file_access(kt_remove_main_t * const main, const f_string_static_t path, uint64_t * const flag_operate, const int access_flags); #endif // _di_kt_remove_preprocess_file_access_ /** -- 1.8.3.1