Add fl_path dependency to utilize fl_path_canonical().
Replace project specific array reallocations with FLL array reallocations.
Add missing directory parameter processing.
fl_conversion
fl_directory
+fl_path
fl_print
fll_error
build_libraries -lc
build_libraries-individual -lfll_error -lfll_print -lfll_program
-build_libraries-individual -lfl_conversion -fl_directory -lfl_print
+build_libraries-individual -lfl_conversion -fl_directory -lfl_path -lfl_print
build_libraries-individual -lf_account -lf_color -lf_compare -lf_console -lf_conversion -lf_directory -lf_file -lf_memory -lf_path -lf_pipe -lf_print -lf_rip -lf_signal -lf_string -lf_time -lf_type_array -lf_utf
build_libraries-individual_thread -lf_thread
build_libraries-level -lfll_2 -lfll_1 -lfll_0
extern "C" {
#endif
-#ifndef _di_kt_remove_dates_resize_
- f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates) {
-
- if (!dates) return F_status_set_error(F_parameter);
-
- if (dates->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
- const f_status_t status = f_memory_resize(dates->size, length, sizeof(kt_remove_date_t), (void **) & dates->array);
- if (F_status_is_error(status)) return status;
-
- dates->size = length;
-
- if (dates->used > dates->size) {
- dates->used = length;
- }
-
- return F_okay;
- }
-#endif // _di_kt_remove_dates_resize_
-
-#ifndef _di_kt_remove_modes_resize_
- f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes) {
-
- if (!modes) return F_status_set_error(F_parameter);
-
- if (modes->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
- const f_status_t status = f_memory_resize(modes->size, length, sizeof(kt_remove_mode_t), (void **) & modes->array);
- if (F_status_is_error(status)) return status;
-
- modes->size = length;
-
- if (modes->used > modes->size) {
- modes->used = length;
- }
-
- return F_okay;
- }
-#endif // _di_kt_remove_modes_resize_
-
#ifndef _di_kt_remove_setting_load_
void kt_remove_setting_load(const f_console_arguments_t arguments, kt_remove_main_t * const main) {
}
}
+ if (main->program.parameters.array[kt_remove_parameter_directory_e].result & f_console_result_found_e) {
+ main->setting.flag |= kt_remove_main_flag_directory_d;
+ main->setting.flag |= kt_remove_main_flag_option_used_d;
+ }
+
if (main->program.parameters.array[kt_remove_parameter_force_e].result & f_console_result_found_e) {
main->setting.flag |= kt_remove_main_flag_force_d;
}
}
if (dates[p]->used + total_locations > dates[p]->size) {
- main->setting.state.status = kt_remove_dates_resize(dates[p]->size + (total_locations - dates[p]->size), dates[p]);
+ main->setting.state.status = f_memory_array_resize(dates[p]->size + (total_locations - dates[p]->size), sizeof(kt_remove_date_t), (void **) &dates[p]->array, &dates[p]->used, &dates[p]->size);
if (F_status_is_error(main->setting.state.status)) {
- kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_dates_resize));
+ kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize));
return;
}
}
if (main->setting.modes.used + total_locations > main->setting.modes.size) {
- main->setting.state.status = kt_remove_modes_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), &main->setting.modes);
+ main->setting.state.status = f_memory_array_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), sizeof(kt_remove_mode_t), (void **) &main->setting.modes.array, &main->setting.modes.used, &main->setting.modes.size);
if (F_status_is_error(main->setting.state.status)) {
- kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_modes_resize));
+ kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize));
return;
}
#endif
/**
- * Resize a date array. @todo migrate this?
- *
- * @param length
- * The new size to use.
- * @param dates
- * The array to resize.
- *
- * Must not be NULL.
- *
- * @return
- * F_okay on success.
- *
- * F_array_too_large (with error bit) if the combined array is too large.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * Errors (with error bit) from: f_memory_resize().
- */
-#ifndef _di_kt_remove_dates_resize_
- extern f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates);
-#endif // _di_kt_remove_dates_resize_
-
-/**
- * Resize a mode array. @todo migrate this?
- *
- * @param length
- * The new size to use.
- * @param modes
- * The array to resize.
- *
- * Must not be NULL.
- *
- * @return
- * F_okay on success.
- *
- * F_array_too_large (with error bit) if the combined array is too large.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * Errors (with error bit) from: f_memory_resize().
- */
-#ifndef _di_kt_remove_modes_resize_
- extern f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes);
-#endif // _di_kt_remove_modes_resize_
-
-/**
* Perform the standard program setting load process.
*
* This prints error messages as appropriate.
"f_utf_is_whitespace",
"fl_conversion_dynamic_partial_to_unsigned_detect",
"fl_conversion_dynamic_to_unsigned_detect",
+ "fl_path_canonical",
"fll_program_parameter_process_context",
"fll_program_parameter_process_empty",
"fll_program_parameter_process_verbosity",
"kt_remove_convert_date_relative",
"kt_remove_convert_timezone",
- "kt_remove_dates_resize",
"kt_remove_get_id_group",
"kt_remove_get_id_user",
- "kt_remove_modes_resize",
};
#endif // _di_kt_remove_f_a_
kt_remove_f_f_utf_is_whitespace_e,
kt_remove_f_fl_conversion_dynamic_partial_to_unsigned_detect_e,
kt_remove_f_fl_conversion_dynamic_to_unsigned_detect_e,
+ kt_remove_f_fl_path_canonical_e,
kt_remove_f_fll_program_parameter_process_context_e,
kt_remove_f_fll_program_parameter_process_empty_e,
kt_remove_f_fll_program_parameter_process_verbosity_e,
extern "C" {
#endif
+
+#ifndef _di_kt_remove_cache_delete_
+ void kt_remove_cache_delete(kt_remove_cache_t * const cache) {
+
+ if (!cache) return;
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->file.string, &cache->file.used, &cache->file.size);
+ }
+#endif // _di_kt_remove_cache_delete_
+
#ifndef _di_kt_remove_main_delete_
void kt_remove_main_delete(kt_remove_main_t * const main) {
if (!main) return;
fll_program_data_delete(&main->program);
+
+ kt_remove_cache_delete(&main->cache);
kt_remove_setting_delete(&main->setting);
}
#endif // _di_kt_remove_main_delete_
#ifndef _di_kt_remove_setting_delete_
- f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting) {
+ void kt_remove_setting_delete(kt_remove_setting_t * const setting) {
- if (!setting) return F_status_set_error(F_parameter);
+ if (!setting) return;
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->buffer.string, &setting->buffer.used, &setting->buffer.size);
f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->files.array, &setting->files.used, &setting->files.size, &f_string_dynamics_delete_callback);
- kt_remove_dates_resize(0, &setting->accessed);
- kt_remove_dates_resize(0, &setting->changed);
- kt_remove_dates_resize(0, &setting->updated);
- kt_remove_modes_resize(0, &setting->modes);
+ f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->accessed.array, &setting->accessed.used, &setting->accessed.size);
+ f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->changed.array, &setting->changed.used, &setting->changed.size);
+ f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->updated.array, &setting->updated.used, &setting->updated.size);
+ f_memory_array_resize(0, sizeof(kt_remove_mode_t), (void **) &setting->modes.array, &setting->modes.used, &setting->modes.size);
f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->groups.array, &setting->groups.used, &setting->groups.size);
f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->users.array, &setting->users.used, &setting->users.size);
f_directory_recurse_do_delete(&setting->recurse);
-
- return F_okay;
}
#endif // _di_kt_remove_setting_delete_
#endif // _di_kt_remove_modes_t_
/**
+ * The program cache.
+ *
+ * buffer: The generic buffer.
+ * file: The current file being processed (generally canonicalized).
+ */
+#ifndef _di_kt_remove_cache_t_
+ typedef struct {
+ f_string_dynamic_t buffer;
+ f_string_dynamic_t file;
+ } kt_remove_cache_t;
+
+ #define kt_remove_cache_t_initialize \
+ { \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ }
+#endif // _di_kt_remove_cache_t_
+
+/**
* The main program settings.
*
* This is passed to the program-specific main entry point to designate program settings.
* program_name: The short name of the program.
* program_name_long: The human friendly name of the program.
*
- * buffer: A string buffer used for caching purposes.
* files: An array of file names (full paths to the files) to remove.
*
* accessed: An array of last accessed dates used for comparison.
f_status_t status_thread;
f_state_t state;
- f_string_dynamic_t buffer;
f_string_dynamics_t files;
kt_remove_dates_t accessed;
kt_remove_main_flag_none_d, \
F_okay, \
macro_f_state_t_initialize_1(kt_remove_allocation_large_d, kt_remove_allocation_small_d, F_okay, 0, 0, &fll_program_standard_signal_handle, 0, 0, 0, 0), \
- f_string_dynamic_t_initialize, \
f_string_dynamics_t_initialize, \
kt_remove_dates_t_initialize, \
kt_remove_dates_t_initialize, \
struct kt_remove_main_t_ {
fll_program_data_t program;
kt_remove_setting_t setting;
+ kt_remove_cache_t cache;
};
#define kt_remove_main_t_initialize \
{ \
fll_program_data_t_initialize, \
kt_remove_setting_t_initialize, \
+ kt_remove_cache_t_initialize, \
}
#endif // _di_kt_remove_main_t_
/**
+ * Delete the program main setting data.
+ *
+ * @param cache
+ * The program main cache data.
+ *
+ * This does not alter setting.state.status.
+ */
+#ifndef _di_kt_remove_cache_delete_
+ extern void kt_remove_cache_delete(kt_remove_cache_t * const cache);
+#endif // _di_kt_remove_cache_delete_
+
+/**
* Deallocate main program data.
*
* @param setting_make
* The program main setting data.
*
* This does not alter setting.state.status.
- *
- * @return
- * F_okay on success.
- *
- * F_parameter (with error bit) if a parameter is invalid.
*/
#ifndef _di_kt_remove_setting_delete_
- extern f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting);
+ extern void kt_remove_setting_delete(kt_remove_setting_t * const setting);
#endif // _di_kt_remove_setting_delete_
#ifdef __cplusplus
if (F_status_is_error(main->setting.state.status)) {
if (F_status_set_fine(main->setting.state.status) == F_number) {
- main->setting.buffer.used = 0;
+ main->cache.buffer.used = 0;
- main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer);
+ main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer);
if (F_status_is_error(main->setting.state.status)) return 0;
gid_t gid = 0;
- main->setting.state.status = f_account_group_id_by_name(main->setting.buffer, &gid);
+ main->setting.state.status = f_account_group_id_by_name(main->cache.buffer, &gid);
if (F_status_is_error(main->setting.state.status)) return 0;
if (main->setting.state.status == F_exist_not) {
if (F_status_is_error(main->setting.state.status)) {
if (F_status_set_fine(main->setting.state.status) == F_number) {
- main->setting.buffer.used = 0;
+ main->cache.buffer.used = 0;
- main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer);
+ main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer);
if (F_status_is_error(main->setting.state.status)) return 0;
uid_t uid = 0;
- main->setting.state.status = f_account_id_by_name(main->setting.buffer, &uid);
+ main->setting.state.status = f_account_id_by_name(main->cache.buffer, &uid);
if (F_status_is_error(main->setting.state.status)) return 0;
if (main->setting.state.status == F_exist_not) {
// @todo consider providing a "follow deep" parameter for recursively following until a non-link is reached.
if (flag & kt_remove_flag_file_operate_follow_d) {
- main->setting.buffer.used = 0;
+ main->cache.buffer.used = 0;
- main->setting.state.status = f_file_link_read(path, F_false, &main->setting.buffer);
+ main->setting.state.status = f_file_link_read(path, F_false, &main->cache.buffer);
if (F_status_is_error(main->setting.state.status)) {
kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), path, f_file_operation_stat_s, fll_error_file_type_link_e);
return;
}
- main->setting.state.status = f_file_remove(main->setting.buffer);
+ main->setting.state.status = f_file_remove(main->cache.buffer);
if (F_status_is_error(main->setting.state.status)) {
- kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->setting.buffer, f_file_operation_delete_s, fll_error_file_type_file_e);
+ kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->cache.buffer, f_file_operation_delete_s, fll_error_file_type_file_e);
return;
}
}
if (status == F_true) {
- main->setting.buffer.used = 0;
+ main->cache.buffer.used = 0;
- status = f_file_link_read(path, F_false, &main->setting.buffer);
+ status = f_file_link_read(path, F_false, &main->cache.buffer);
if (F_status_is_error(status)) {
fl_print_format(" link_read_failure %ui%r", main->program.output.to, F_status_set_fine(status), f_string_eol_s);
f_file_stream_lock(main->program.output.to);
fl_print_format(" follow %r%r", main->program.output.to, (main->setting.flag & kt_remove_main_flag_follow_d) ? kt_remove_yes_s : kt_remove_no_s, f_string_eol_s);
- fl_print_format(" to '%Q'%r", main->program.output.to, main->setting.buffer, f_string_eol_s);
+ fl_print_format(" to '%Q'%r", main->program.output.to, main->cache.buffer, f_string_eol_s);
f_file_stream_unlock(main->program.output.to);
}
for (f_number_unsigned_t i = 0; i < main->setting.files.used; ++i) {
- kt_remove_operate_file(main, main->setting.files.array[i]);
+ main->cache.file.used = 0;
+
+ fl_path_canonical(main->setting.files.array[i], &main->cache.file);
+
+ if (F_status_is_error(main->setting.state.status)) {
+ kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(fl_path_canonical), main->setting.files.array[i], f_file_operation_process_s, fll_error_file_type_path_e);
+
+ break;
+ }
+
+ kt_remove_operate_file(main, main->cache.file);
if ((main->setting.flag & kt_remove_main_flag_simulate_d) && i + 1 < main->setting.files.used && (F_status_is_error_not(main->setting.state.status) || F_status_set_fine(main->setting.state.status) == F_interrupt)) {
f_print_dynamic(f_string_eol_s, main->program.output.to);
// FLL-1 includes.
#include <fll/level_1/conversion.h>
#include <fll/level_1/directory.h>
+#include <fll/level_1/path.h>
#include <fll/level_1/print.h>
// FLL-2 includes.