]> Kevux Git Server - kevux-tools/commitdiff
Bugfix: File not found errors with f_file_access().
authorKevin Day <Kevin@kevux.org>
Tue, 17 Jun 2025 03:48:44 +0000 (22:48 -0500)
committerKevin Day <Kevin@kevux.org>
Tue, 17 Jun 2025 03:48:44 +0000 (22:48 -0500)
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.

sources/c/program/kevux/tools/remove/main/common/print.c
sources/c/program/kevux/tools/remove/main/common/print.h
sources/c/program/kevux/tools/remove/main/preprocess.c
sources/c/program/kevux/tools/remove/main/preprocess.h

index 2cf7e40b012f0adc19c6219348bdcbe90446a16a..c8e3ed14ff80c07dc1eb3719889dfb730d5116f3 100644 (file)
@@ -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",
index 27e5037d0fab7827b8e304e1f5f4a666b98255e0..a16b68c022b463bbce02b5ca80b9c7bfe683b801 100644 (file)
@@ -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,
index b56b5253b6e1cbde01d9449dd97e0a5eec2d7aba..05709801948629287ce26c874551ca99ff5d3f85 100644 (file)
@@ -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_
 
index 6701818f7890b03c76f97c7b383c7cdd4c417a69..e5096d4dded59ecedf512dfebe816f0277e1d823 100644 (file)
@@ -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_
 
 /**