From: Kevin Day Date: Sat, 30 May 2020 22:33:09 +0000 (-0500) Subject: Update: pipe and fifo, replace f_directory_mode with f_mode, f_file_copy() X-Git-Tag: 0.5.0~232 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=63bf439d58264cda9a363334a4176604bcf3d910;p=fll Update: pipe and fifo, replace f_directory_mode with f_mode, f_file_copy() Stick to only using fifo terminology in file types. Replace f_directory_mode with f_mode, a global type to be shared between f_file, f_directory, and anything else. Update f_file_copy() to use f_mode instead of mode_t. This allows the caller to just send the mode. The copy function already stats the file and processes it per file type, so it can make the decision on which mode to use. This alleviates the need for the caller to also perform a file type stat check. --- diff --git a/level_0/f_directory/c/directory_type.h b/level_0/f_directory/c/directory_type.h index 86884e8..458d852 100644 --- a/level_0/f_directory/c/directory_type.h +++ b/level_0/f_directory/c/directory_type.h @@ -32,7 +32,7 @@ extern "C" { f_string_dynamics directory; // S_IFDIR f_string_dynamics regular; // S_IFREG f_string_dynamics link; // S_IFLNK - f_string_dynamics pipe; // S_IFIFO + f_string_dynamics fifo; // S_IFIFO f_string_dynamics socket; // S_IFSOCK f_string_dynamics unknown; } f_directory_listing; @@ -54,7 +54,7 @@ extern "C" { if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.directory) \ if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.regular) \ if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.link) \ - if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.pipe) \ + if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.fifo) \ if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.socket) \ if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.unknown) @@ -64,7 +64,7 @@ extern "C" { if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.directory) \ if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.regular) \ if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.link) \ - if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.pipe) \ + if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.fifo) \ if (!F_status_is_error(status)) f_macro_string_dynamics_destroy(status, listing.socket) \ if (!F_status_is_error(status)) f_macro_string_dynamics_delete(status, listing.unknown) @@ -74,7 +74,7 @@ extern "C" { f_macro_string_dynamics_delete_simple(listing.directory) \ f_macro_string_dynamics_delete_simple(listing.regular) \ f_macro_string_dynamics_delete_simple(listing.link) \ - f_macro_string_dynamics_delete_simple(listing.pipe) \ + f_macro_string_dynamics_delete_simple(listing.fifo) \ f_macro_string_dynamics_delete_simple(listing.socket) \ f_macro_string_dynamics_delete_simple(listing.unknown) @@ -84,79 +84,12 @@ extern "C" { f_macro_string_dynamics_destroy_simple(listing.directory) \ f_macro_string_dynamics_destroy_simple(listing.regular) \ f_macro_string_dynamics_destroy_simple(listing.link) \ - f_macro_string_dynamics_destroy_simple(listing.pipe) \ + f_macro_string_dynamics_destroy_simple(listing.fifo) \ f_macro_string_dynamics_destroy_simple(listing.socket) \ f_macro_string_dynamics_destroy_simple(listing.unknown) #endif // _di_f_directory_listing_ /** - * A structure representing a set of modes intended to be used by directory operations. - * - * A small set of macros are provider to help simplify assigning modes. - * - * The pipe (S_IFIFO) is intentionally not supported. - */ -#ifndef _di_f_directory_mode_ - typedef struct { - mode_t block; // S_IFBLK - mode_t character; // S_IFCHR - mode_t directory; // S_IFDIR - mode_t regular; // S_IFREG - mode_t link; // S_IFLNK - mode_t socket; // S_IFSOCK - mode_t unknown; - } f_directory_mode; - - #define f_directory_mode_initialize { \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - } - - #define f_macro_directory_mode_set_default(modes) \ - modes.block = f_file_mode_all_rw; \ - modes.character = f_file_mode_all_rw; \ - modes.directory = f_file_mode_all_rwx; \ - modes.regular = f_file_mode_all_rw; \ - modes.link = f_file_mode_all_rw; \ - modes.socket = f_file_mode_all_rw; \ - modes.unknown = f_file_mode_all_rw; - - #define f_macro_directory_mode_set_default_umask(modes, mask) \ - modes.block = f_file_mode_all_rw & ~mask; \ - modes.character = f_file_mode_all_rw & ~mask; \ - modes.directory = f_file_mode_all_rwx & ~mask; \ - modes.regular = f_file_mode_all_rw & ~mask; \ - modes.link = f_file_mode_all_rw & ~mask; \ - modes.socket = f_file_mode_all_rw & ~mask; \ - modes.unknown = f_file_mode_all_rw & ~mask; - - #define f_macro_directory_mode_set_all(modes, mode) \ - modes.block = mode; \ - modes.character = mode; \ - modes.directory = mode; \ - modes.regular = mode; \ - modes.link = mode; \ - modes.socket = mode; \ - modes.unknown = mode; - - #define f_macro_directory_mode_set_common(modes, mode_directory, mode_file, mode_link) \ - modes.directory = mode_directory; \ - modes.regular = mode_file; \ - modes.link = mode_link; - - #define f_macro_directory_mode_set_uncommon(modes, mode_block, mode_character, mode_socket, mode_unknown) \ - modes.block = mode_block; \ - modes.character = mode_character; \ - modes.socket = mode_socket; \ - modes.unknown = mode_unknown; -#endif // _di_f_directory_mode_ - -/** * An association of a path and a status code. * * The allocation macros apply to the path. diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index dfb1678..b4a97ae 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -119,31 +119,29 @@ extern "C" { #endif // _di_f_file_close_ #ifndef _di_f_file_copy_ - f_return_status f_file_copy(const f_string source, const f_string destination, const mode_t mode, const f_number_unsigned size_block, const bool exclusive) { + f_return_status f_file_copy(const f_string source, const f_string destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive) { f_status status = F_none; struct stat source_stat; - // remove the file type from the mode. - const mode_t mode_access = (~f_file_type_mask) & mode; - memset(&source_stat, 0, sizeof(struct stat)); status = private_f_file_stat(source, F_false, &source_stat); if (F_status_is_error(status)) return status; if (f_macro_file_type_is_regular(source_stat.st_mode)) { - status = private_f_file_create(destination, mode_access, exclusive); + + status = private_f_file_create(destination, (~f_file_type_mask) & mode.regular, exclusive); if (F_status_is_error(status)) return status; if (!exclusive) { - status = private_f_file_change_mode(destination, mode_access); + status = private_f_file_change_mode(destination, (~f_file_type_mask) & mode.regular); if (F_status_is_error(status)) return status; } return private_f_file_copy_content(source, destination, size_block == 0 ? f_file_default_read_size : size_block); } else if (f_macro_file_type_is_directory(source_stat.st_mode)) { - status = private_f_file_create_directory(destination, mode_access); + status = private_f_file_create_directory(destination, (~f_file_type_mask) & mode.directory); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_file_found || exclusive) { @@ -151,7 +149,7 @@ extern "C" { } } - status = private_f_file_change_mode(destination, mode_access); + status = private_f_file_change_mode(destination, (~f_file_type_mask) & mode.directory); if (F_status_is_error(status)) return status; return F_none; @@ -178,7 +176,7 @@ extern "C" { return F_none; } else if (f_macro_file_type_is_fifo(source_stat.st_mode)) { - status = private_f_file_create_fifo(destination, mode_access); + status = private_f_file_create_fifo(destination, (~f_file_type_mask) & mode.fifo); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_file_found || exclusive) { @@ -186,13 +184,13 @@ extern "C" { } } - status = private_f_file_change_mode(destination, mode_access); + status = private_f_file_change_mode(destination, (~f_file_type_mask) & mode.fifo); if (F_status_is_error(status)) return status; return F_none; } else if (f_macro_file_type_is_socket(source_stat.st_mode)) { - status = private_f_file_create_node(destination, f_macro_file_type_get(source_stat.st_mode) | mode_access, source_stat.st_rdev); + status = private_f_file_create_node(destination, f_macro_file_type_get(source_stat.st_mode) | (~f_file_type_mask) & mode.socket, source_stat.st_rdev); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_file_found || exclusive) { @@ -200,13 +198,13 @@ extern "C" { } } - status = private_f_file_change_mode(destination, mode_access); + status = private_f_file_change_mode(destination, (~f_file_type_mask) & mode.socket); if (F_status_is_error(status)) return status; return F_none; } else if (f_macro_file_type_is_block(source_stat.st_mode) || f_macro_file_type_is_character(source_stat.st_mode)) { - status = private_f_file_create_node(destination, f_macro_file_type_get(source_stat.st_mode) | mode_access, source_stat.st_rdev); + status = private_f_file_create_node(destination, f_macro_file_type_get(source_stat.st_mode) | (~f_file_type_mask) & mode.block, source_stat.st_rdev); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_file_found || exclusive) { @@ -214,7 +212,7 @@ extern "C" { } } - status = private_f_file_change_mode(destination, mode_access); + status = private_f_file_change_mode(destination, (~f_file_type_mask) & mode.block); if (F_status_is_error(status)) return status; return F_none; diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index b18c04a..bf15f36 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -66,8 +66,6 @@ extern "C" { /** * Provide file type macros. - * - * Note: f_file_type_pipe and f_file_type_fifo are the same. */ #ifndef _di_f_file_type_ #define f_file_type_mask S_IFMT @@ -77,7 +75,6 @@ extern "C" { #define f_file_type_directory S_IFDIR #define f_file_type_fifo S_IFIFO #define f_file_type_link S_IFLNK - #define f_file_type_pipe S_IFIFO #define f_file_type_regular S_IFREG #define f_file_type_socket S_IFSOCK @@ -88,7 +85,6 @@ extern "C" { #define f_macro_file_type_is_directory(mode) f_macro_file_type_get(mode) == f_file_type_directory #define f_macro_file_type_is_fifo(mode) f_macro_file_type_get(mode) == f_file_type_fifo #define f_macro_file_type_is_link(mode) f_macro_file_type_get(mode) == f_file_type_link - #define f_macro_file_type_is_pipe(mode) f_macro_file_type_get(mode) == f_file_type_pipe #define f_macro_file_type_is_regular(mode) f_macro_file_type_get(mode) == f_file_type_regular #define f_macro_file_type_is_socket(mode) f_macro_file_type_get(mode) == f_file_type_socket #endif // _di_f_file_type_ @@ -540,7 +536,7 @@ extern "C" { * @param destination * The path to copy to. * @param mode - * The file mode assigned to the destination file. + * The file mode assigned to the destination file, based on the file type. * @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. @@ -572,7 +568,7 @@ extern "C" { * F_file_write (with error bit) on file write error. */ #ifndef _di_f_file_copy_ - extern f_return_status f_file_copy(const f_string source, const f_string destination, const mode_t mode, const f_number_unsigned size_block, const bool exclusive); + extern f_return_status f_file_copy(const f_string source, const f_string destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive); #endif // _di_f_file_copy_ /** diff --git a/level_0/f_type/c/type.h b/level_0/f_type/c/type.h index e056c9a..782b991 100644 --- a/level_0/f_type/c/type.h +++ b/level_0/f_type/c/type.h @@ -13,6 +13,7 @@ // libc includes #include #include +#include #include #ifdef __cplusplus @@ -214,6 +215,76 @@ extern "C" { #define f_gcc_attribute_visibility_protected __attribute__((visibility("protected"))) #endif // _di_f_gcc_specific_ + +/** + * A structure representing a set of modes intended to be used by file or directory operations. + */ +#ifndef _di_f_mode_ + typedef struct { + mode_t block; // S_IFBLK + mode_t character; // S_IFCHR + mode_t directory; // S_IFDIR + mode_t fifo; // S_IFIFO + mode_t regular; // S_IFREG + mode_t link; // S_IFLNK + mode_t socket; // S_IFSOCK + mode_t unknown; + } f_mode; + + #define f_mode_initialize { \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + } + + #define f_macro_mode_set_default(mode) \ + mode.block = f_file_mode_all_rw; \ + mode.character = f_file_mode_all_rw; \ + mode.directory = f_file_mode_all_rwx; \ + mode.fifo = f_file_mode_all_rw; \ + mode.regular = f_file_mode_all_rw; \ + mode.link = f_file_mode_all_rw; \ + mode.socket = f_file_mode_all_rw; \ + mode.unknown = f_file_mode_all_rw; + + #define f_macro_mode_set_default_umask(mode, mask) \ + mode.block = f_file_mode_all_rw & ~mask; \ + mode.character = f_file_mode_all_rw & ~mask; \ + mode.directory = f_file_mode_all_rwx & ~mask; \ + mode.fifo = f_file_mode_all_rw & ~mask; \ + mode.regular = f_file_mode_all_rw & ~mask; \ + mode.link = f_file_mode_all_rw & ~mask; \ + mode.socket = f_file_mode_all_rw & ~mask; \ + mode.unknown = f_file_mode_all_rw & ~mask; + + #define f_macro_mode_set_all(mode, value) \ + mode.block = value; \ + mode.character = value; \ + mode.directory = value; \ + mode.fifo = value; \ + mode.regular = value; \ + mode.link = value; \ + mode.socket = value; \ + mode.unknown = value; + + #define f_macro_mode_set_common(mode, value_directory, value_file, value_link) \ + mode.directory = value_directory; \ + mode.regular = value_file; \ + mode.link = value_link; + + #define f_macro_mode_set_uncommon(mode, value_block, value_character, value_fifo, value_socket, value_unknown) \ + mode.block = value_block; \ + mode.character = value_character; \ + mode.fifo = value_fifo; \ + mode.socket = value_socket; \ + mode.unknown = value_unknown; +#endif // _di_f_directory_mode_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index b737924..f651127 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_fl_directory_clone_ - f_return_status fl_directory_clone(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status fl_directory_clone(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = f_directory_exists(source); if (F_status_is_error(status)) return status; @@ -40,6 +40,10 @@ extern "C" { if (F_status_is_error(status)) return status; } + if (verbose) { + fprintf(verbose, "Cloned '%s' to '%s'.%c", source, destination, f_string_eol); + } + f_string_static static_source = { source, source_length, source_length }; f_string_static static_destination = { destination, destination_length, destination_length }; @@ -62,12 +66,12 @@ extern "C" { } // for } - return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, failures); + return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, verbose, failures); } #endif // _di_fl_directory_clone_ #ifndef _di_fl_directory_clone_content_ - f_return_status fl_directory_clone_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status fl_directory_clone_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = f_directory_exists(source); if (F_status_is_error(status)) return status; @@ -99,12 +103,12 @@ extern "C" { } // for } - return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, failures); + return private_fl_directory_clone(static_source, static_destination, role, size_block, exclusive, verbose, failures); } #endif // _di_fl_directory_clone_content_ #ifndef _di_fl_directory_copy_ - f_return_status fl_directory_copy(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status fl_directory_copy(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = f_directory_exists(source); if (F_status_is_error(status)) return status; @@ -126,6 +130,10 @@ extern "C" { if (F_status_is_error(status)) return status; } + if (verbose) { + fprintf(verbose, "Copied '%s' to '%s'.%c", source, destination, f_string_eol); + } + f_string_static static_source = { source, source_length, source_length }; f_string_static static_destination = { destination, destination_length, destination_length }; @@ -148,12 +156,12 @@ extern "C" { } // for } - return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, failures); + return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, verbose, failures); } #endif // _di_fl_directory_copy_ #ifndef _di_fl_directory_copy_content_ - f_return_status fl_directory_copy_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status fl_directory_copy_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = f_directory_exists(source); if (F_status_is_error(status)) return status; @@ -185,7 +193,7 @@ extern "C" { } // for } - return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, failures); + return private_fl_directory_copy(static_source, static_destination, mode, size_block, exclusive, verbose, failures); } #endif // _di_fl_directory_copy_content_ diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index d848c6c..fdb489d 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -74,6 +74,9 @@ extern "C" { * @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. @@ -105,7 +108,7 @@ extern "C" { * @see f_file_clone() */ #ifndef _di_fl_directory_clone_ - extern f_return_status fl_directory_clone(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures); + extern f_return_status fl_directory_clone(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures); #endif // _di_fl_directory_clone_ /** @@ -140,6 +143,9 @@ extern "C" { * @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. @@ -171,7 +177,7 @@ extern "C" { * @see f_file_clone() */ #ifndef _di_fl_directory_clone_content_ - extern f_return_status fl_directory_clone_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures); + extern f_return_status fl_directory_clone_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures); #endif // _di_fl_directory_clone_content_ /** @@ -202,9 +208,9 @@ extern "C" { * @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 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. @@ -236,7 +242,7 @@ extern "C" { * @see f_file_copy() */ #ifndef _di_fl_directory_copy_ - extern f_return_status fl_directory_copy(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures); + extern f_return_status fl_directory_copy(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures); #endif // _di_fl_directory_copy_ /** @@ -269,6 +275,9 @@ extern "C" { * @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. @@ -300,7 +309,7 @@ extern "C" { * @see f_file_copy() */ #ifndef _di_fl_directory_copy_content_ - extern f_return_status fl_directory_copy_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures); + extern f_return_status fl_directory_copy_content(const f_string source, const f_string destination, const f_string_length source_length, const f_string_length destination_length, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures); #endif // _di_fl_directory_copy_content_ /** diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index b043b13..7158021 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -6,7 +6,7 @@ extern "C" { #endif #if !defined(_di_fl_directory_clone_) - f_return_status private_fl_directory_clone(const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status private_fl_directory_clone(const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = F_none; f_directory_listing listing = f_directory_listing_initialize; @@ -24,37 +24,37 @@ extern "C" { f_string_length 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, failures); + status = private_fl_directory_clone_file(listing.block.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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, failures); + status = private_fl_directory_clone_file(listing.character.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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, failures); + status = private_fl_directory_clone_file(listing.regular.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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, failures); + status = private_fl_directory_clone_file(listing.link.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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, failures); + status = private_fl_directory_clone_file(listing.socket.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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, failures); + status = private_fl_directory_clone_file(listing.unknown.array[i], source, destination, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_delete_simple(listing.unknown); @@ -126,7 +126,7 @@ extern "C" { } } - status = private_fl_directory_clone(source_sub, destination_sub, role, size_block, exclusive, failures); + status = private_fl_directory_clone(source_sub, destination_sub, role, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_delete_simple(listing.directory); @@ -140,7 +140,7 @@ extern "C" { #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 file, const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status private_fl_directory_clone_file(const f_string_static file, const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { char path_source[source.used + file.used + 2]; char path_destination[destination.used + file.used + 2]; @@ -227,12 +227,16 @@ extern "C" { return F_failure; } + if (verbose) { + fprintf(verbose, "Cloned '%s' to '%s'.%c", source.string, destination.string, f_string_eol); + } + 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 source, const f_string_static destination, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status private_fl_directory_copy(const f_string_static source, const f_string_static destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { f_status status = F_none; f_directory_listing listing = f_directory_listing_initialize; @@ -250,37 +254,43 @@ extern "C" { f_string_length failures_used = failures ? 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.block, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.block.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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.character, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.character.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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_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.regular, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.regular.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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.link, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.link.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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.socket, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.socket.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_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.unknown, size_block, exclusive, failures); + status = private_fl_directory_copy_file(listing.unknown.array[i], source, destination, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_delete_simple(listing.unknown); @@ -338,7 +348,7 @@ extern "C" { if (F_status_is_error(status)) break; } - status = private_fl_directory_copy(source_sub, destination_sub, mode, size_block, exclusive, failures); + status = private_fl_directory_copy(source_sub, destination_sub, mode, size_block, exclusive, verbose, failures); } // for f_macro_string_dynamics_delete_simple(listing.directory); @@ -352,7 +362,7 @@ extern "C" { #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 file, const f_string_static source, const f_string_static destination, const mode_t mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) { + f_return_status private_fl_directory_copy_file(const f_string_static file, const f_string_static source, const f_string_static destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) { char path_source[source.used + file.used + 2]; char path_destination[destination.used + file.used + 2]; @@ -439,6 +449,10 @@ extern "C" { return F_failure; } + if (verbose) { + fprintf(verbose, "Copied '%s' to '%s'.%c", source.string, destination.string, f_string_eol); + } + return F_none; } #endif // !defined(_di_fl_directory_copy_file_) @@ -539,8 +553,8 @@ extern "C" { else if (mode == f_file_type_link) { names = &listing->link; } - else if (mode == f_file_type_pipe) { - names = &listing->pipe; + else if (mode == f_file_type_fifo) { + names = &listing->fifo; } else if (mode == f_file_type_socket) { names = &listing->socket; diff --git a/level_1/fl_directory/c/private-directory.h b/level_1/fl_directory/c/private-directory.h index 698faa8..7df04b1 100644 --- a/level_1/fl_directory/c/private-directory.h +++ b/level_1/fl_directory/c/private-directory.h @@ -35,6 +35,9 @@ extern "C" { * @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. @@ -66,7 +69,7 @@ extern "C" { * @see fl_directory_clone() */ #if !defined(_di_fl_directory_clone_) - extern f_return_status private_fl_directory_clone(const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; + extern f_return_status private_fl_directory_clone(const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; #endif // !defined(_di_fl_directory_clone_) /** @@ -93,6 +96,9 @@ extern "C" { * @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. @@ -124,7 +130,7 @@ extern "C" { * @see fl_directory_clone() */ #if !defined(_di_fl_directory_clone_file_) - extern f_return_status private_fl_directory_clone_file(const f_string_static file, const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; + extern f_return_status private_fl_directory_clone_file(const f_string_static file, const f_string_static source, const f_string_static destination, const bool role, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; #endif // !defined(_di_fl_directory_clone_file_) /** @@ -139,13 +145,16 @@ extern "C" { * The destination file path. * Must be NULL terminated. * @param mode - * The directory modes. + * 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. @@ -177,7 +186,7 @@ extern "C" { * @see fl_directory_copy() */ #if !defined(_di_fl_directory_copy_) - extern f_return_status private_fl_directory_copy(const f_string_static source, const f_string_static destination, const f_directory_mode mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; + extern f_return_status private_fl_directory_copy(const f_string_static source, const f_string_static destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; #endif // !defined(_di_fl_directory_copy_) /** @@ -195,13 +204,16 @@ extern "C" { * The destination file path. * Must be NULL terminated. * @param mode - * The directory 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. @@ -233,7 +245,7 @@ extern "C" { * @see fl_directory_copy() */ #if !defined(_di_fl_directory_copy_file_) - extern f_return_status private_fl_directory_copy_file(const f_string_static file, const f_string_static source, const f_string_static destination, const mode_t mode, const f_number_unsigned size_block, const bool exclusive, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; + extern f_return_status private_fl_directory_copy_file(const f_string_static file, const f_string_static source, const f_string_static destination, const f_mode mode, const f_number_unsigned size_block, const bool exclusive, FILE *verbose, f_directory_statuss *failures) f_gcc_attribute_visibility_internal; #endif // !defined(_di_fl_directory_copy_file_) /**