if (!path.used) return;
}
- if (recurse->depth < recurse->depth_max) {
- ++recurse->depth;
-
- private_fl_directory_do_recurse(recurse);
-
- --recurse->depth;
-
- if (F_status_is_error(recurse->state.status)) return;
-
- if (recurse->state.status == F_done) {
- recurse->state.status = F_okay;
-
- return;
- }
- }
-
const uint32_t flag_actions[] = {
recurse->flag & f_directory_recurse_do_flag_before_d ? f_directory_recurse_do_flag_before_d : 0,
f_directory_recurse_do_flag_action_d,
}
if (flag_actions[action]) {
+ if (flag_actions[action] & f_directory_recurse_do_flag_action_d) {
+ if (recurse->depth < recurse->depth_max) {
+ recurse->state.status = F_okay;
+
+ ++recurse->depth;
+
+ private_fl_directory_do_recurse(recurse);
+
+ --recurse->depth;
+
+ if (F_status_is_error(recurse->state.status)) return;
+
+ if (recurse->state.status == F_done) {
+ recurse->state.status = F_okay;
+
+ return;
+ }
+
+ // Reset the path after operating on child directories.
+ recurse->path.used = path.used;
+ recurse->path.string[recurse->path.used] = 0;
+ }
+ }
+
recurse->state.status = F_okay;
recurse->action(recurse, path, flag_actions[action] | recurse->flag | f_directory_recurse_do_flag_directory_d);
* The handle() gives the caller more power to do things like report errors or even ignore errors.
* When ignoring errors, be careful about modifications as some may put the project in an unusual state.
*
+ * The before action happens before the directory recurse or if not recursing then before the action.
+ * The directory recurse happens before the action.
+ * The action happens before the after.
+ *
* The action() and handle() should check if the recurse is NULL (and any other appropraite NULL checks).
*
* General behavior flow:
* 1. Check recurse.action existence (if not _di_level_1_parameter_checking_), flag is f_directory_recurse_do_flag_none_d.
* 2. Check path.used and allocation recurse.path, flag is f_directory_recurse_do_flag_path_d (even if handle() changes error bit, if path.used is 0, then the function always returns here).
- * 3. If recurse.depth < recurse.depth_max, then recurse into directory contents.
- * 3.1 Open directory stream, flag is f_directory_recurse_do_flag_list_d.
- * 3.2 Read directory stream, flag is f_directory_recurse_do_flag_path_list_d ('.' and '..' are skipped).
- * 3.3 Allocate sub-path onto recurse.path, flag is f_directory_recurse_do_flag_path_d.
- * 3.4 Process before state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_before_d.
- * 3.5 Process action state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_action_d.
- * 3.5.1 If type is directory (flag has f_directory_recurse_do_flag_directory_d), then increase recurse.depth and recurse (repeat step (3) for this sub-directory).
- * 3.6 Process after state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_after_d.
- * 3.7 Close directory stream, flag is f_directory_recurse_do_flag_clean_d | f_directory_recurse_do_flag_path_list_d.
- * 4. Process top-level directory.
- * 4.1 Process before state on path, flag is f_directory_recurse_do_flag_before_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
- * 4.2 Process action state on path, flag is f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
- * 4.3 Process after state on path, flag is f_directory_recurse_do_flag_after_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
+ * 3. Process before state on path, flag is f_directory_recurse_do_flag_before_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
+ * 4. If recurse.depth < recurse.depth_max, then recurse into directory contents.
+ * 4.1. Open directory stream, flag is f_directory_recurse_do_flag_list_d.
+ * 4.2. Read directory stream, flag is f_directory_recurse_do_flag_path_list_d ('.' and '..' are skipped).
+ * 4.3. Allocate sub-path onto recurse.path, flag is f_directory_recurse_do_flag_path_d.
+ * 4.4. Process before state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_before_d.
+ * 4.5. If type is directory (flag has f_directory_recurse_do_flag_directory_d), then increase recurse.depth and recurse (repeat step (4) for this sub-directory).
+ * 4.6. Process action state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_action_d.
+ * 4.7. Process after state on path, flag is (type code of file/directory) | f_directory_recurse_do_flag_after_d.
+ * 4.8. Close directory stream, flag is f_directory_recurse_do_flag_clean_d | f_directory_recurse_do_flag_path_list_d.
+ * 5. Process top-level directory.
+ * 5.1. Process action state on path, flag is f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
+ * 5.2. Process after state on path, flag is f_directory_recurse_do_flag_after_d | f_directory_recurse_do_flag_directory_d | recurse.flag.
*
* @param path
* The directory file path.