Rewrite the fl_directory_* recursive functions, simplifying their design.
Add a max recursion depth.
I have a toleration limit on the number of arguments in a function and this just reached a limit.
Given that many of the parameters can be logically grouped and are also are also passed to other functions, implement a new structure.
While this simply changes where the complexity/problems happen, this does alleviate the number of arguments concerns.
Fix an accidental 'const const' declaration.
Don't error on max recurse depth.
This should just stop recursing for that directory and not generated an error.
if (width_max < 1) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- const const uint8_t width = f_macro_utf_byte_width_is(*character);
+ const uint8_t width = f_macro_utf_byte_width_is(*character);
if (width == 0) {
// There are no ASCII private characters.
#endif
#ifndef _di_fl_directory_clone_
- f_return_status fl_directory_clone(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status fl_directory_clone(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse) {
#ifndef _di_level_1_parameter_checking_
if (source) return F_status_set_error(F_parameter);
if (destination) return F_status_set_error(F_parameter);
if (F_status_is_error(status)) return status;
if (status == F_true) {
- if (exclusive) {
+ if (recurse.exclusive) {
return F_status_set_error(F_directory_found);
}
if (F_status_is_error(status)) return status;
}
- if (verbose) {
- fprintf(verbose, "Cloned '%s' to '%s'.%c", source, destination, f_string_eol[0]);
+ if (recurse.verbose) {
+ fprintf(recurse.verbose, "Cloned '%s' to '%s'.%c", source, destination, f_string_eol[0]);
}
f_string_static_t static_source = { source, source_length, source_length };
} // for
}
- return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, verbose, failures);
+ if (recurse.depth_max == 0) {
+ return status;
+ }
+
+ return private_fl_directory_clone(static_source, static_destination, role, recurse, 1);
}
#endif // _di_fl_directory_clone_
#ifndef _di_fl_directory_clone_content_
- f_return_status fl_directory_clone_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status fl_directory_clone_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse) {
#ifndef _di_level_1_parameter_checking_
if (source) return F_status_set_error(F_parameter);
if (destination) return F_status_set_error(F_parameter);
} // for
}
- return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, verbose, failures);
+ if (recurse.depth_max == 0) {
+ return status;
+ }
+
+ return private_fl_directory_clone(static_source, static_destination, role, recurse, 1);
}
#endif // _di_fl_directory_clone_content_
#ifndef _di_fl_directory_copy_
- f_return_status fl_directory_copy(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status fl_directory_copy(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse) {
#ifndef _di_level_1_parameter_checking_
if (source) return F_status_set_error(F_parameter);
if (destination) return F_status_set_error(F_parameter);
if (F_status_is_error(status)) return status;
if (status == F_true) {
- if (exclusive) {
+ if (recurse.exclusive) {
return F_status_set_error(F_directory_found);
}
if (F_status_is_error(status)) return status;
}
- if (verbose) {
- fprintf(verbose, "Copied '%s' to '%s'.%c", source, destination, f_string_eol[0]);
+ if (recurse.verbose) {
+ fprintf(recurse.verbose, "Copied '%s' to '%s'.%c", source, destination, f_string_eol[0]);
}
f_string_static_t static_source = { source, source_length, source_length };
} // for
}
- return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, verbose, failures);
+ if (recurse.depth_max == 0) {
+ return status;
+ }
+
+ return private_fl_directory_copy(static_source, static_destination, mode, recurse, 1);
}
#endif // _di_fl_directory_copy_
#ifndef _di_fl_directory_copy_content_
- f_return_status fl_directory_copy_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status fl_directory_copy_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse) {
#ifndef _di_level_1_parameter_checking_
if (source) return F_status_set_error(F_parameter);
if (destination) return F_status_set_error(F_parameter);
} // for
}
- return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, verbose, failures);
+ if (recurse.depth_max == 0) {
+ return status;
+ }
+
+ return private_fl_directory_copy(static_source, static_destination, mode, recurse, 1);
}
#endif // _di_fl_directory_copy_content_
#endif
/**
+ * An association of a path and a status code.
+ *
+ * The allocation macros apply to the path.
+ *
+ * depth_max:
+ * The max recursion depth.
+ * size_block:
+ * The default number of chunks to read at a time with each chunk being 1-byte.
+ * Must be greater than 0.
+ * exclusive:
+ * If TRUE, will fail when file already exists.
+ * If FALSE, will not fail if file already exists (existing file will be replaced).
+ * verbose:
+ * Set to 0 to not print copy operation values on successful copy.
+ * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
+ * failures:
+ * A list of paths and their respective status codes for clone failures.
+ * If 0, then this and statuses are ignored.
+ */
+#ifndef _di_fl_directory_recurse_t_
+ #define fl_directory_recurse_depth_max 65535
+
+ typedef struct {
+ f_number_unsigned_t depth_max;
+ f_number_unsigned_t size_block;
+ bool exclusive;
+ FILE *verbose;
+ f_directory_statuss_t *failures;
+ } fl_directory_recurse_t;
+
+ #define fl_directory_recurse_t_initialize { fl_directory_recurse_depth_max, f_file_default_read_size, F_false, 0, 0 }
+#endif // _di_fl_directory_recurse_t_
+
+/**
* Copy a directory and its contents, as well as its file mode and possibly the owner and group..
*
* The paths must not contain NULL except for the terminating NULL.
* If TRUE, will copy the owner and group ids.
* If FALSE, will not copy the owner and group ids.
* (In both cases the file mode is copied.)
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for clone failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see f_file_clone()
*/
#ifndef _di_fl_directory_clone_
- extern f_return_status fl_directory_clone(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures);
+ extern f_return_status fl_directory_clone(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse);
#endif // _di_fl_directory_clone_
/**
* If TRUE, will copy the owner and group ids.
* If FALSE, will not copy the owner and group ids.
* (In both cases the file mode is copied.)
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for clone failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see f_file_clone()
*/
#ifndef _di_fl_directory_clone_content_
- extern f_return_status fl_directory_clone_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures);
+ extern f_return_status fl_directory_clone_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse);
#endif // _di_fl_directory_clone_content_
/**
* The length of the destination path.
* @param mode
* The directory modes.
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Set to 0 to use default block read size.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for copy failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see f_file_copy()
*/
#ifndef _di_fl_directory_copy_
- extern f_return_status fl_directory_copy(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures);
+ extern f_return_status fl_directory_copy(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse);
#endif // _di_fl_directory_copy_
/**
* The length of the destination path.
* @param mode
* The directory modes.
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Set to 0 to use default block read size.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for copy failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see f_file_copy()
*/
#ifndef _di_fl_directory_copy_content_
- extern f_return_status fl_directory_copy_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures);
+ extern f_return_status fl_directory_copy_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse);
#endif // _di_fl_directory_copy_content_
/**
#endif
#if !defined(_di_fl_directory_clone_)
- f_return_status private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) {
f_status_t status = F_none;
f_directory_listing_t listing = f_directory_listing_t_initialize;
status = F_none;
- f_array_length_t i = 0;
-
int directory_fd = 0;
- f_string_length_t failures_used = failures ? failures->used : 0;
-
- for (; F_status_is_fine(status) && i < listing.block.used; i++) {
- status = private_fl_directory_clone_file(listing.block.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.block);
-
- for (i = 0; F_status_is_fine(status) && i < listing.character.used; i++) {
- status = private_fl_directory_clone_file(listing.character.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.character);
-
- for (i = 0; F_status_is_fine(status) && i < listing.regular.used; i++) {
- status = private_fl_directory_clone_file(listing.regular.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.regular);
-
- for (i = 0; F_status_is_fine(status) && i < listing.link.used; i++) {
- status = private_fl_directory_clone_file(listing.link.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
+ f_string_length_t failures_used = recurse.failures ? recurse.failures->used : 0;
- f_macro_string_dynamics_t_delete_simple(listing.link);
-
- for (i = 0; F_status_is_fine(status) && i < listing.socket.used; i++) {
- status = private_fl_directory_clone_file(listing.socket.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.socket);
-
- for (i = 0; F_status_is_fine(status) && i < listing.unknown.used; i++) {
- status = private_fl_directory_clone_file(listing.unknown.array[i], source, destination, role, size_block, exclusive, verbose, failures);
- } // for
+ {
+ f_string_dynamics_t *list[] = {
+ &listing.block,
+ &listing.character,
+ &listing.regular,
+ &listing.link,
+ &listing.fifo,
+ &listing.socket,
+ &listing.unknown,
+ };
+
+ uint8_t i = 0;
+ f_array_length_t j = 0;
+
+ for (; i < 7; i++) {
+ for (j = 0; F_status_is_fine(status) && j < list[i]->used; j++) {
+ status = private_fl_directory_clone_file(list[i]->array[i], source, destination, role, recurse);
+ } // for
- f_macro_string_dynamics_t_delete_simple(listing.unknown);
+ f_macro_string_dynamics_t_delete_simple((*list[i]));
+ } // for
+ }
- for (i = 0; F_status_is_fine(status) && i < listing.directory.used; i++) {
+ for (f_array_length_t i = 0; F_status_is_fine(status) && i < listing.directory.used; i++) {
f_string_static_t source_sub = f_string_static_t_initialize;
f_string_static_t destination_sub = f_string_static_t_initialize;
if (F_status_is_error(status)) break;
if (status == F_true) {
- if (exclusive) {
+ if (recurse.exclusive) {
status = F_status_set_error(F_directory_found);
break;
}
}
}
- status = private_fl_directory_clone(source_sub, destination_sub, role, size_block, exclusive, verbose, failures);
+ if (depth < recurse.depth_max) {
+ status = private_fl_directory_clone(source_sub, destination_sub, role, recurse, depth + 1);
+ }
} // for
f_macro_string_dynamics_t_delete_simple(listing.directory);
if (F_status_is_error(status)) return status;
- if (failures && failures_used < failures->used) return F_failure;
+ if (recurse.failures && failures_used < recurse.failures->used) return F_failure;
return F_none;
}
#endif // !defined(_di_fl_directory_clone_)
#if !defined(_di_fl_directory_clone_file_)
- f_return_status private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse) {
char path_source[source.used + file.used + 2];
char path_destination[destination.used + file.used + 2];
path_destination[destination.used] = f_path_separator[0];
path_destination[destination.used + file.used + 1] = 0;
- f_status_t status = f_file_clone(path_source, path_destination, role, size_block, exclusive);
+ f_status_t status = f_file_clone(path_source, path_destination, role, recurse.size_block, recurse.exclusive);
if (F_status_is_error(status) || status == F_unsupported) {
if (status == F_status_set_error(F_memory_allocation) || status == F_status_set_error(F_memory_reallocation)) {
return F_status_set_error(status);
}
- if (!failures) return F_failure;
+ if (!recurse.failures) return F_failure;
const f_status_t status_failure = status;
- f_macro_memory_structure_macro_increment(status, (*failures), 1, f_memory_default_allocation_step, f_macro_directory_statuss_t_resize, F_buffer_too_large);
+ f_macro_memory_structure_macro_increment(status, (*recurse.failures), 1, f_memory_default_allocation_step, f_macro_directory_statuss_t_resize, F_buffer_too_large);
if (F_status_is_error(status)) return status;
f_directory_status_t failure = f_directory_status_t_initialize;
failure.path.string[size] = 0;
}
- failures->array[failures->used].path.string = failure.path.string;
- failures->array[failures->used].path.used = size;
- failures->array[failures->used].path.size = size + 1;
- failures->array[failures->used].status = status_failure;
- failures->used++;
+ recurse.failures->array[recurse.failures->used].path.string = failure.path.string;
+ recurse.failures->array[recurse.failures->used].path.used = size;
+ recurse.failures->array[recurse.failures->used].path.size = size + 1;
+ recurse.failures->array[recurse.failures->used].status = status_failure;
+ recurse.failures->used++;
return F_failure;
}
- if (verbose) {
- fprintf(verbose, "Cloned '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]);
+ if (recurse.verbose) {
+ fprintf(recurse.verbose, "Cloned '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]);
}
return F_none;
#endif // !defined(_di_fl_directory_clone_file_)
#if !defined(_di_fl_directory_copy_)
- f_return_status private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) {
f_status_t status = F_none;
f_directory_listing_t listing = f_directory_listing_t_initialize;
status = F_none;
- f_array_length_t i = 0;
-
int directory_fd = 0;
- f_string_length_t failures_used = failures ? failures->used : 0;
+ f_string_length_t failures_used = recurse.failures ? recurse.failures->used : 0;
- for (; F_status_is_fine(status) && i < listing.block.used; i++) {
- status = private_fl_directory_copy_file(listing.block.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.block);
-
- for (i = 0; F_status_is_fine(status) && i < listing.character.used; i++) {
- status = private_fl_directory_copy_file(listing.character.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.character);
-
- for (i = 0; F_status_is_fine(status) && i < listing.fifo.used; i++) {
- status = private_fl_directory_copy_file(listing.fifo.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.fifo);
-
- for (i = 0; F_status_is_fine(status) && i < listing.regular.used; i++) {
- status = private_fl_directory_copy_file(listing.regular.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.regular);
-
- for (i = 0; F_status_is_fine(status) && i < listing.link.used; i++) {
- status = private_fl_directory_copy_file(listing.link.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.link);
-
- for (i = 0; F_status_is_fine(status) && i < listing.socket.used; i++) {
- status = private_fl_directory_copy_file(listing.socket.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
-
- f_macro_string_dynamics_t_delete_simple(listing.socket);
-
- for (i = 0; F_status_is_fine(status) && i < listing.unknown.used; i++) {
- status = private_fl_directory_copy_file(listing.unknown.array[i], source, destination, mode, size_block, exclusive, verbose, failures);
- } // for
+ {
+ f_string_dynamics_t *list[] = {
+ &listing.block,
+ &listing.character,
+ &listing.regular,
+ &listing.link,
+ &listing.fifo,
+ &listing.socket,
+ &listing.unknown,
+ };
+
+ uint8_t i = 0;
+ f_array_length_t j = 0;
+
+ for (; i < 7; i++) {
+ for (j = 0; F_status_is_fine(status) && j < list[i]->used; j++) {
+ status = private_fl_directory_copy_file(list[i]->array[i], source, destination, mode, recurse);
+ } // for
- f_macro_string_dynamics_t_delete_simple(listing.unknown);
+ f_macro_string_dynamics_t_delete_simple((*list[i]));
+ } // for
+ }
- for (i = 0; F_status_is_fine(status) && i < listing.directory.used; i++) {
+ for (f_array_length_t i = 0; F_status_is_fine(status) && i < listing.directory.used; i++) {
f_string_static_t source_sub = f_string_static_t_initialize;
f_string_static_t destination_sub = f_string_static_t_initialize;
if (F_status_is_error(status)) break;
if (status == F_true) {
- if (exclusive) {
+ if (recurse.exclusive) {
status = F_status_set_error(F_directory_found);
break;
}
if (F_status_is_error(status)) break;
}
- status = private_fl_directory_copy(source_sub, destination_sub, mode, size_block, exclusive, verbose, failures);
+ if (depth < recurse.depth_max) {
+ status = private_fl_directory_copy(source_sub, destination_sub, mode, recurse, depth + 1);
+ }
} // for
f_macro_string_dynamics_t_delete_simple(listing.directory);
if (F_status_is_error(status)) return status;
- if (failures && failures_used < failures->used) return F_failure;
+ if (recurse.failures && failures_used < recurse.failures->used) return F_failure;
return F_none;
}
#endif // !defined(_di_fl_directory_copy_)
#if !defined(_di_fl_directory_copy_file_)
- f_return_status private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) {
+ f_return_status private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) {
char path_source[source.used + file.used + 2];
char path_destination[destination.used + file.used + 2];
path_destination[destination.used] = f_path_separator[0];
path_destination[destination.used + file.used + 1] = 0;
- f_status_t status = f_file_copy(path_source, path_destination, mode, size_block, exclusive);
+ f_status_t status = f_file_copy(path_source, path_destination, mode, recurse.size_block, recurse.exclusive);
if (F_status_is_error(status) || status == F_unsupported) {
if (status == F_status_set_error(F_memory_allocation) || status == F_status_set_error(F_memory_reallocation)) {
return F_status_set_error(status);
}
- if (!failures) return F_failure;
+ if (!recurse.failures) return F_failure;
const f_status_t status_failure = status;
- f_macro_memory_structure_macro_increment(status, (*failures), 1, f_memory_default_allocation_step, f_macro_directory_statuss_t_resize, F_buffer_too_large);
+ f_macro_memory_structure_macro_increment(status, (*recurse.failures), 1, f_memory_default_allocation_step, f_macro_directory_statuss_t_resize, F_buffer_too_large);
if (F_status_is_error(status)) return status;
f_directory_status_t failure = f_directory_status_t_initialize;
failure.path.string[size] = 0;
}
- failures->array[failures->used].path.string = failure.path.string;
- failures->array[failures->used].path.used = size;
- failures->array[failures->used].path.size = size + 1;
- failures->array[failures->used].status = status_failure;
- failures->used++;
+ recurse.failures->array[recurse.failures->used].path.string = failure.path.string;
+ recurse.failures->array[recurse.failures->used].path.used = size;
+ recurse.failures->array[recurse.failures->used].path.size = size + 1;
+ recurse.failures->array[recurse.failures->used].status = status_failure;
+ recurse.failures->used++;
return F_failure;
}
- if (verbose) {
- fprintf(verbose, "Copied '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]);
+ if (recurse.verbose) {
+ fprintf(recurse.verbose, "Copied '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]);
}
return F_none;
* If TRUE, will copy the owner and group ids.
* If FALSE, will not copy the owner and group ids.
* (In both cases the file mode is copied.)
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for clone failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
+ * @param depth
+ * The current depth.
*
* @return
* F_none on success.
* @see fl_directory_clone()
*/
#if !defined(_di_fl_directory_clone_)
- extern f_return_status private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) f_gcc_attribute_visibility_internal;
+ extern f_return_status private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) f_gcc_attribute_visibility_internal;
#endif // !defined(_di_fl_directory_clone_)
/**
* If TRUE, will copy the owner and group ids.
* If FALSE, will not copy the owner and group ids.
* (In both cases the file mode is copied.)
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for clone failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see fl_directory_clone()
*/
#if !defined(_di_fl_directory_clone_file_)
- extern f_return_status private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const bool role, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) f_gcc_attribute_visibility_internal;
+ extern f_return_status private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse) f_gcc_attribute_visibility_internal;
#endif // !defined(_di_fl_directory_clone_file_)
/**
* Must be NULL terminated.
* @param mode
* The mode for each file type.
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for copy failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
+ * @param depth
+ * The current depth.
*
* @return
* F_none on success.
* @see fl_directory_copy()
*/
#if !defined(_di_fl_directory_copy_)
- extern f_return_status private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) f_gcc_attribute_visibility_internal;
+ extern f_return_status private_fl_directory_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) f_gcc_attribute_visibility_internal;
#endif // !defined(_di_fl_directory_copy_)
/**
* Must be NULL terminated.
* @param mode
* The mode for each file type.
- * @param size_block
- * The default number of chunks to read at a time with each chunk being 1-byte.
- * Must be greater than 0.
- * @param exclusive
- * If TRUE, will fail when file already exists.
- * If FALSE, will not fail if file already exists (existing file will be replaced).
- * @param verbose
- * Set to 0 to not print copy operation values on successful copy.
- * Set to a valid file pointer, such as f_type_output (stdout), to print on successful copy.
- * @param failures
- * A list of paths and their respective status codes for copy failures.
- * If 0, then this and statuses is ignored.
+ * @param recurse
+ * The directory recurse data.
*
* @return
* F_none on success.
* @see fl_directory_copy()
*/
#if !defined(_di_fl_directory_copy_file_)
- extern f_return_status private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const f_number_unsigned_t size_block, const bool exclusive, FILE *verbose, f_directory_statuss_t *failures) f_gcc_attribute_visibility_internal;
+ extern f_return_status private_fl_directory_copy_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) f_gcc_attribute_visibility_internal;
#endif // !defined(_di_fl_directory_copy_file_)
/**
* F_name (with error bit) on path name error.
* F_parameter (with error bit) if a parameter is invalid.
* F_read_only (with error bit) if file is read-only.
- * F_recurse (with error bit) if recursion failed, due to max depth reached.
* F_failure (with error bit) for any other error.
*/
#ifndef _di_fll_file_mode_set_all_
* F_name (with error bit) on path name error.
* F_parameter (with error bit) if a parameter is invalid.
* F_read_only (with error bit) if file is read-only.
- * F_recurse (with error bit) if recursion failed, due to max depth reached.
* F_failure (with error bit) for any other error.
*/
#ifndef _di_fll_file_role_change_all_
#if !defined(_di_fll_file_mode_set_all_)
f_return_status private_fll_file_mode_set_all(const f_string_t path, const mode_t mode, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) {
-
- if (depth >= depth_max) return F_status_set_error(F_recurse);
-
f_status_t status = F_none;
status = f_directory_is(path);
break;
}
- status = private_fll_file_mode_set_all(path_sub, mode, depth_max, depth + 1);
- if (F_status_is_error(status)) break;
+ if (depth < depth_max) {
+ status = private_fll_file_mode_set_all(path_sub, mode, depth_max, depth + 1);
+ if (F_status_is_error(status)) break;
+ }
} // for
f_macro_string_dynamics_t_delete_simple(listing.directory);
#if !defined(_di_fll_file_role_change_all_)
f_return_status private_fll_file_role_change_all(const f_string_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) {
-
- if (depth >= depth_max) return F_status_set_error(F_recurse);
-
f_status_t status = F_none;
status = f_directory_is(path);
break;
}
- status = private_fll_file_role_change_all(path_sub, uid, gid, dereference, depth_max, depth + 1);
- if (F_status_is_error(status)) break;
+ if (depth < depth_max) {
+ status = private_fll_file_role_change_all(path_sub, uid, gid, dereference, depth_max, depth + 1);
+ if (F_status_is_error(status)) break;
+ }
} // for
f_macro_string_dynamics_t_delete_simple(listing.directory);
memcpy(path_source.string, source.string, source.used);
+ fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize;
+
+ if (data.verbosity == fake_verbosity_verbose) {
+ recurse.verbose = f_type_output;
+ }
+
+ recurse.failures = &failures;
+
for (f_array_length_t i = 0; i < files.used; i++) {
if (files.array[i].used == 0) continue;
}
if ((*status = f_directory_is(path_source.string)) == F_true) {
- *status = fl_directory_copy_content(path_source.string, destination.string, path_source.used, destination.used, mode, f_file_default_read_size, F_false, (data.verbosity == fake_verbosity_verbose) ? f_type_output : 0, &failures);
+ *status = fl_directory_copy_content(path_source.string, destination.string, path_source.used, destination.used, mode, recurse);
if (F_status_is_error(*status)) {
if (data.verbosity == fake_verbosity_verbose) {