const uint16_t flag_operate = kt_remove_preprocess_file(main, path, 0);
- if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & (kt_remove_main_flag_simulate_d)) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) {
+ if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & kt_remove_main_flag_simulate_d) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) {
main->setting.state.status = flag_operate & kt_remove_flag_file_operate_directory_d
? kt_remove_operate_file_recurse(main, path, flag_operate)
: kt_remove_operate_file_remove(main, path, flag_operate);
+ }
- if (F_status_is_error_not(main->setting.state.status)) {
- kt_remove_operate_memory_save(main, path, flag_operate);
+ if (F_status_is_error_not(main->setting.state.status)) {
+ kt_remove_operate_memory_save(main, path, flag_operate);
+
+ if (F_status_is_error(main->setting.state.status)) {
+ kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(kt_remove_operate_memory_save), path, f_file_operation_process_s, fll_error_file_type_path_e);
}
}
if (!main->cache.memory.used) return;
- // @todo check list and then set F_remove_not as appropriate.
- // *flag_operate |= kt_remove_flag_file_operate_processed_d
+ f_range_t range = f_range_t_initialize;
+ f_number_unsigned_t i = 0;
+
+ if (main->setting.flag & kt_remove_main_flag_recurse_d) {
+ for (; i < main->cache.memory.used; ++i) {
+
+ if (kt_remove_signal_check(main)) return;
+ if (!main->cache.memory.array[i].used) continue;
+
+ // The memory cache is nulless and top-most directories end in slashes.
+ range.start = 0;
+ range.stop = main->cache.memory.array[i].used - 1;
+
+ if (main->cache.memory.array[i].string[range.stop] == f_path_separator_s.string[0]) {
+ if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) {
+ *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+ break;
+ }
+
+ // Perform exact match without the trailing directory slash.
+ if (range.stop) {
+ --range.stop;
+ }
+
+ if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) {
+ *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+ break;
+ }
+ }
+ else {
+ if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) {
+ *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+ break;
+ }
+ }
+ } // for
+ }
+ else {
+
+ // Only perform exact matches when not using recursion.
+ for (; i < main->cache.memory.used; ++i) {
+
+ if (kt_remove_signal_check(main)) return;
+
+ if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) {
+ *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+ break;
+ }
+ } // for
+ }
}
#endif // _di_kt_remove_operate_memory_check_
return;
}
- // @todo
+ main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.memory.array, &main->cache.memory.used, &main->cache.memory.size);
+
+ // Find any child paths that would be included by this and remove them from the paths list.
+ if (F_status_is_error_not(main->setting.state.status) && (flag_operate & kt_remove_flag_file_operate_directory_d)) {
+ main->cache.buffer.used = 0;
+
+ main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.buffer.string, &main->cache.buffer.used, &main->cache.buffer.size);
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.buffer);
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.buffer);
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ const f_range_t range = macro_f_range_t_initialize_2(main->cache.buffer.used);
+ f_number_unsigned_t i = 0;
+
+ for (; i < main->cache.memory.used; ++i) {
+
+ if (kt_remove_signal_check(main)) return;
+ if (main->cache.buffer.used > main->cache.memory.array[i].used) continue;
+
+ if (f_compare_dynamic_partial_dynamic(main->cache.buffer, main->cache.memory.array[i], range) == F_equal_to) break;
+ } // for
+
+ // Swap the first and the last paths and then remove the last path.
+ if (i < main->cache.memory.used) {
+ const f_string_static_t temporary = macro_f_string_dynamic_t_initialize_1(main->cache.memory.array[i].string, main->cache.memory.array[i].size, main->cache.memory.array[i].used);
+
+ main->cache.memory.array[i].string = main->cache.memory.array[main->cache.memory.used].string;
+ main->cache.memory.array[i].size = main->cache.memory.array[main->cache.memory.used].size;
+ main->cache.memory.array[i].used = main->cache.memory.array[main->cache.memory.used].used;
+
+ main->cache.memory.array[main->cache.memory.used].string = temporary.string;
+ main->cache.memory.array[main->cache.memory.used].size = temporary.size;
+ main->cache.memory.array[main->cache.memory.used--].used = 0;
+ }
+ }
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ main->cache.memory.array[main->cache.memory.used].used = 0;
+
+ if (flag_operate & kt_remove_flag_file_operate_directory_d) {
+ main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.memory.array[main->cache.memory.used].string, &main->cache.memory.array[main->cache.memory.used].used, &main->cache.memory.array[main->cache.memory.used].size);
+ }
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.memory.array[main->cache.memory.used]);
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ if (flag_operate & kt_remove_flag_file_operate_directory_d) {
+ main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.memory.array[main->cache.memory.used]);
+ }
+ }
+
+ if (F_status_is_error_not(main->setting.state.status)) {
+ ++main->cache.memory.used;
+ main->setting.state.status = F_okay;
+ }
}
#endif // _di_kt_remove_operate_memory_save_