From: Kevin Day Date: Thu, 14 Apr 2022 04:04:24 +0000 (-0500) Subject: Update: Implement file statistics flag enumeration, dereferencing/no-dereferencing... X-Git-Tag: 0.5.10~216 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=9d623c7067078dccd568ba2f08dc20014a5be74f;p=fll Update: Implement file statistics flag enumeration, dereferencing/no-dereferencing, and also use F_stream_not. While writing the unit tests for the f_file project I noticed an oversight in the design. The dereferencing logic needs to be designated rather than assumed. This requires changing the parameters to functions. Now is the time to break the API as the official stable release is not made. This takes the minimalistic approach to changing the API. I can imagine better designs where I pass the file stat flag everywhere rather than sometimes passing the file stat flag and other times passing a dereference boolean. This is a larger change in which I wish to avoid. Improvements to this can be made for the next development series. The roles can be merged into the file statistics flags. The roles of group and owner are separated. For the purposes of limiting changes, both owner and group are treated the same. The next development cycle will be expected to improve upon this. The exclusive boolean is now merged into the file statistics flags. The fake program must be updated. A new functionality for designating when to dereference and when not to. The default behavior is to dereference. This means that the new option is "no_dereference". To always favor the dereference by default, the file statistics flag is a "reference" flag used to designate that something must not dereference. The f_file_descriptor() function should return F_stream_not. This makes more sense as it only fails when the file descriptor is not a valid file stream. As mentioned above, I was in the process of updating the tests. This includes some test updates. --- diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists.c b/level_0/f_directory/tests/unit/c/test-directory-exists.c index d3dcca6..0feb2cb 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-exists.c +++ b/level_0/f_directory/tests/unit/c/test-directory-exists.c @@ -59,7 +59,7 @@ void test__f_directory_exists__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_stat, false); @@ -78,7 +78,7 @@ void test__f_directory_exists__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_directory/tests/unit/c/test-directory-exists_at.c b/level_0/f_directory/tests/unit/c/test-directory-exists_at.c index eb9156a..84d611a 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-exists_at.c +++ b/level_0/f_directory/tests/unit/c/test-directory-exists_at.c @@ -61,7 +61,7 @@ void test__f_directory_exists_at__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_fstatat, false); @@ -80,7 +80,7 @@ void test__f_directory_exists_at__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_directory/tests/unit/c/test-directory-is.c b/level_0/f_directory/tests/unit/c/test-directory-is.c index df82271..a93d7a3 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-is.c +++ b/level_0/f_directory/tests/unit/c/test-directory-is.c @@ -59,7 +59,7 @@ void test__f_directory_is__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_stat, false); @@ -78,7 +78,7 @@ void test__f_directory_is__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_directory/tests/unit/c/test-directory-is_at.c b/level_0/f_directory/tests/unit/c/test-directory-is_at.c index 6c88285..afc6531 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-is_at.c +++ b/level_0/f_directory/tests/unit/c/test-directory-is_at.c @@ -61,7 +61,7 @@ void test__f_directory_is_at__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_fstatat, false); @@ -80,7 +80,7 @@ void test__f_directory_is_at__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch.c b/level_0/f_directory/tests/unit/c/test-directory-touch.c index af9d2f4..303f37f 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-touch.c +++ b/level_0/f_directory/tests/unit/c/test-directory-touch.c @@ -126,7 +126,7 @@ void test__f_directory_touch__fails(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; @@ -161,7 +161,7 @@ void test__f_directory_touch__works(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_directory/tests/unit/c/test-directory-touch_at.c b/level_0/f_directory/tests/unit/c/test-directory-touch_at.c index 6c941bb..6cd970d 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-touch_at.c +++ b/level_0/f_directory/tests/unit/c/test-directory-touch_at.c @@ -126,7 +126,7 @@ void test__f_directory_touch_at__fails(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; @@ -161,7 +161,7 @@ void test__f_directory_touch_at__works(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | S_IFDIR; diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index b4fe549..467ccb4 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -72,29 +72,28 @@ extern "C" { #endif // _di_f_file_access_at_ #ifndef _di_f_file_clone_ - f_status_t f_file_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) { + f_status_t f_file_clone(const f_string_static_t source, const f_string_static_t destination, const f_number_unsigned_t size_block, const uint8_t flag) { if (!source.used || !destination.used) { return F_data_not; } - f_status_t status = F_none; struct stat source_stat; memset(&source_stat, 0, sizeof(struct stat)); - status = private_f_file_stat(source, F_false, &source_stat); + f_status_t status = private_f_file_stat(source, !(flag & f_file_stat_flag_reference_e), &source_stat); if (F_status_is_error(status)) return status; if (macro_f_file_type_is_regular(source_stat.st_mode)) { - status = private_f_file_create(destination, source_stat.st_mode, exclusive); + status = private_f_file_create(destination, source_stat.st_mode, flag & f_file_stat_flag_exclusive_e); if (F_status_is_error(status)) return status; status = private_f_file_mode_set(destination, source_stat.st_mode); if (F_status_is_error(status)) return status; - if (role) { - status = private_f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, F_false); + if (flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { + status = private_f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, !(flag & f_file_stat_flag_reference_e)); if (F_status_is_error(status)) return status; } @@ -105,7 +104,7 @@ extern "C" { status = private_f_file_link(destination, source); if (F_status_set_fine(status) == F_file_found) { - if (exclusive) return status; + if (flag & f_file_stat_flag_exclusive_e) return status; } else if (F_status_is_error(status)) { return status; @@ -114,8 +113,8 @@ extern "C" { status = private_f_file_mode_set(destination, source_stat.st_mode); if (F_status_is_error(status)) return status; - if (role) { - status = private_f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, F_false); + if (flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { + status = private_f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, !(flag & f_file_stat_flag_reference_e)); if (F_status_is_error(status)) return status; } @@ -147,7 +146,7 @@ extern "C" { #endif // _di_f_file_close_flush_ #ifndef _di_f_file_copy_ - f_status_t f_file_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) { + f_status_t f_file_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 uint8_t flag) { if (!source.used || !destination.used) { return F_data_not; @@ -158,11 +157,11 @@ extern "C" { memset(&source_stat, 0, sizeof(struct stat)); - status = private_f_file_stat(source, F_false, &source_stat); + status = private_f_file_stat(source, !(flag & f_file_stat_flag_reference_e), &source_stat); if (F_status_is_error(status)) return status; if (macro_f_file_type_is_regular(source_stat.st_mode)) { - status = private_f_file_create(destination, (~F_file_type_mask_d) & mode.regular, exclusive); + status = private_f_file_create(destination, (~F_file_type_mask_d) & mode.regular, flag & f_file_stat_flag_exclusive_e); if (F_status_is_error(status)) return status; status = private_f_file_mode_set(destination, (~F_file_type_mask_d) & mode.regular); @@ -175,7 +174,7 @@ extern "C" { status = private_f_file_create_directory(destination, (~F_file_type_mask_d) & mode.directory); if (F_status_is_error(status)) { - if (F_status_set_fine(status) != F_file_found || exclusive) { + if (F_status_set_fine(status) != F_file_found || flag & f_file_stat_flag_exclusive_e) { return status; } } @@ -202,7 +201,7 @@ extern "C" { f_string_dynamic_resize(0, &target); if (F_status_is_error(status)) { - if (F_status_set_fine(status) != F_file_found || exclusive) { + if (F_status_set_fine(status) != F_file_found || flag & f_file_stat_flag_exclusive_e) { return status; } } @@ -214,7 +213,7 @@ extern "C" { status = private_f_file_create_fifo(destination, (~F_file_type_mask_d) & mode.fifo); if (F_status_is_error(status)) { - if (F_status_set_fine(status) != F_file_found || exclusive) { + if (F_status_set_fine(status) != F_file_found || flag & f_file_stat_flag_exclusive_e) { return status; } } @@ -229,7 +228,7 @@ extern "C" { status = private_f_file_create_node(destination, macro_f_file_type_get(source_stat.st_mode) | ((~F_file_type_mask_d) & mode.socket), source_stat.st_rdev); if (F_status_is_error(status)) { - if (F_status_set_fine(status) != F_file_found || exclusive) { + if (F_status_set_fine(status) != F_file_found || flag & f_file_stat_flag_exclusive_e) { return status; } } @@ -244,7 +243,7 @@ extern "C" { status = private_f_file_create_node(destination, macro_f_file_type_get(source_stat.st_mode) | ((~F_file_type_mask_d) & mode.block), source_stat.st_rdev); if (F_status_is_error(status)) { - if (F_status_set_fine(status) != F_file_found || exclusive) { + if (F_status_set_fine(status) != F_file_found || flag & f_file_stat_flag_exclusive_e) { return status; } } @@ -376,7 +375,7 @@ extern "C" { file->id = fileno(file->stream); if (file->id == -1) { - return F_status_set_error(F_file); + return F_status_set_error(F_stream_not); } return F_none; @@ -384,7 +383,7 @@ extern "C" { #endif // _di_f_file_descriptor_ #ifndef _di_f_file_exists_ - f_status_t f_file_exists(const f_string_static_t path) { + f_status_t f_file_exists(const f_string_static_t path, const bool dereference) { if (!path.used) { return F_data_not; @@ -394,7 +393,7 @@ extern "C" { memset(&stat_file, 0, sizeof(struct stat)); - const f_status_t status = private_f_file_stat(path, F_false, &stat_file); + const f_status_t status = private_f_file_stat(path, dereference, &stat_file); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_file_found_not) { @@ -441,7 +440,7 @@ extern "C" { #endif // _di_f_file_flush_ #ifndef _di_f_file_group_read_ - f_status_t f_file_group_read(const f_string_static_t path, gid_t * const group) { + f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, gid_t * const group) { #ifndef _di_level_0_parameter_checking_ if (!group) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -455,7 +454,7 @@ extern "C" { memset(&stat_file, 0, sizeof(struct stat)); { - const f_status_t status = private_f_file_stat(path, F_true, &stat_file); + const f_status_t status = private_f_file_stat(path, dereference, &stat_file); if (F_status_is_error(status)) return status; } @@ -581,19 +580,19 @@ extern "C" { if (linkat(at_id_target, target.string, at_id_point, point.string, flag) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EFBIG || errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == EINTR) return F_status_set_error(F_interrupt); if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ELOOP) return F_status_set_error(F_loop); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); if (errno == ENOENT) return F_status_set_error(F_file_found_not); - if (errno == ENOTDIR) return F_status_set_error(F_directory_not); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOSPC) return F_status_set_error(F_space_not); + if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == ETXTBSY) return F_status_set_error(F_busy); @@ -1290,7 +1289,7 @@ extern "C" { #endif // _di_f_file_mode_from_string_ #ifndef _di_f_file_mode_read_ - f_status_t f_file_mode_read(const f_string_static_t path, mode_t * const mode) { + f_status_t f_file_mode_read(const f_string_static_t path, const bool dereference, mode_t * const mode) { #ifndef _di_level_0_parameter_checking_ if (!mode) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -1304,7 +1303,7 @@ extern "C" { memset(&stat_file, 0, sizeof(struct stat)); { - const f_status_t status = private_f_file_stat(path, F_true, &stat_file); + const f_status_t status = private_f_file_stat(path, dereference, &stat_file); if (F_status_is_error(status)) return status; } @@ -1519,7 +1518,7 @@ extern "C" { #endif // _di_f_file_open_at_ #ifndef _di_f_file_owner_read_ - f_status_t f_file_owner_read(const f_string_static_t path, uid_t * const owner) { + f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, uid_t * const owner) { #ifndef _di_level_0_parameter_checking_ if (!owner) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ @@ -1533,7 +1532,7 @@ extern "C" { memset(&stat_file, 0, sizeof(struct stat)); { - const f_status_t status = private_f_file_stat(path, F_true, &stat_file); + const f_status_t status = private_f_file_stat(path, dereference, &stat_file); if (F_status_is_error(status)) return status; } @@ -1719,18 +1718,18 @@ extern "C" { if (unlinkat(at_id, path.string, flag) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EBUSY) return F_status_set_error(F_busy); + if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == EIO) return F_status_set_error(F_input_output); if (errno == EISDIR) return F_status_set_error(F_file_type_directory); if (errno == ELOOP) return F_status_set_error(F_loop); if (errno == ENAMETOOLONG) return F_status_set_error(F_name); - if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == ENOENT) return F_status_set_error(F_file_found_not); if (errno == ENOMEM) return F_status_set_error(F_memory_not); if (errno == ENOTDIR) return F_status_set_error(F_directory_not); if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); return F_status_set_error(F_failure); } @@ -1782,6 +1781,7 @@ extern "C" { if (renameat(at_id, source.string, to_id, destination.string) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EBUSY) return F_status_set_error(F_busy); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EFAULT) return F_status_set_error(F_buffer); @@ -1799,7 +1799,6 @@ extern "C" { if (errno == EPERM) return F_status_set_error(F_prohibited); if (errno == EROFS) return F_status_set_error(F_read_only); if (errno == EXDEV) return F_status_set_error(F_mount); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); return F_status_set_error(F_failure); } @@ -2710,15 +2709,15 @@ extern "C" { memset(&stat_file, 0, sizeof(struct stat)); if (fstatat(at_id, path.string, &stat_file, flag) < 0) { - if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EBADF) return F_status_set_error(F_directory_descriptor); if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == ENAMETOOLONG) return F_status_set_error(F_name); + if (errno == ENOENT) return F_file_found_not; if (errno == ENOMEM) return F_status_set_error(F_memory_not); - if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == ENOTDIR) return F_status_set_error(F_directory_not); - if (errno == ENOENT) return F_file_found_not; - if (errno == EACCES) return F_status_set_error(F_access_denied); + if (errno == EOVERFLOW) return F_status_set_error(F_number_overflow); if (errno == ELOOP) return F_status_set_error(F_loop); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); return F_status_set_error(F_file_stat); } diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index bf16a02..1ed2602 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -100,8 +100,8 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_not (with error bit) the file does not exist. * F_loop (with error bit) on loop error. * F_memory_not (with error bit) if out of memory. @@ -131,16 +131,18 @@ extern "C" { * The path to the file to copy from. * @param destination * The path to copy to. - * @param role - * 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. * 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 flag + * If f_file_stat_flag_exclusive_e, will fail when file already exists. + * If not f_file_stat_flag_exclusive_e, will not fail if file already exists (existing file will be replaced). + * + * If f_file_stat_flag_reference_e, will operate directly on a link rather than what it references. + * If not f_file_stat_flag_reference_e, will dereference any links. + * + * If either f_file_stat_flag_group_e or f_file_stat_flag_owner_e, will copy the owner and group ids. + * If neither f_file_stat_flag_group_e nor f_file_stat_flag_owner_e, will not copy the owner and group ids. * * @return * F_none on success. @@ -170,7 +172,7 @@ extern "C" { * F_failure (with error bit) for any other error. */ #ifndef _di_f_file_clone_ - extern f_status_t f_file_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); + extern f_status_t f_file_clone(const f_string_static_t source, const f_string_static_t destination, const f_number_unsigned_t size_block, const uint8_t flag); #endif // _di_f_file_clone_ /** @@ -245,9 +247,12 @@ extern "C" { * @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 flag + * If f_file_stat_flag_exclusive_e, will fail when file already exists. + * If not f_file_stat_flag_exclusive_e, will not fail if file already exists (existing file will be replaced). + * + * If f_file_stat_flag_reference_e, will operate directly on a link rather than what it references. + * If not f_file_stat_flag_reference_e, will dereference any links. * * @return * F_none on success. @@ -274,7 +279,7 @@ extern "C" { * F_failure (with error bit) for any other error. */ #ifndef _di_f_file_copy_ - extern f_status_t f_file_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); + extern f_status_t f_file_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 uint8_t flag); #endif // _di_f_file_copy_ /** @@ -338,6 +343,7 @@ extern "C" { * * F_access_denied (with error bit) on access denied. * F_busy (with error bit) if file system is too busy to perform write. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_file_found (with error bit) if a file was found while exclusive is TRUE. * F_file_open_max (with error bit) when system-wide max open files is reached. @@ -422,8 +428,8 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file was found while exclusive is TRUE. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. * F_loop (with error bit) on loop error. @@ -488,8 +494,8 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file was found while exclusive is TRUE. * F_filesystem_quota_block (with error bit) if file system's disk blocks or ififos are exhausted. * F_loop (with error bit) on loop error. @@ -559,8 +565,8 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file was found while exclusive is TRUE. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. * F_loop (with error bit) on loop error. @@ -588,7 +594,7 @@ extern "C" { * F_none is returned on success. * * F_parameter (with error bit) if a parameter is invalid. - * F_file (with error bit) if file is not a valid stream. + * F_stream_not (with error bit) if file is not a valid stream. * * @see fileno() */ @@ -604,6 +610,9 @@ extern "C" { * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks. + * Set to FALSE to operate on the symlink itself. * * @return * F_true if path was found. @@ -618,10 +627,11 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * + * @see lstat() * @see stat() */ #ifndef _di_f_file_exists_ - extern f_status_t f_file_exists(const f_string_static_t path); + extern f_status_t f_file_exists(const f_string_static_t path, const bool dereference); #endif // _di_f_file_exists_ /** @@ -643,6 +653,7 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) on access denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_false (with error bit) on unknown/unhandled errors. * F_loop (with error bit) on loop error. @@ -685,6 +696,9 @@ extern "C" { * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks (often is what is desired). + * Set to FALSE to operate on the symlink itself. * @param group * The id of the file's group. * @@ -701,10 +715,10 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * - * @see fstat() + * @see stat() */ #ifndef _di_f_file_group_read_ - extern f_status_t f_file_group_read(const f_string_static_t path, uid_t * const group); + extern f_status_t f_file_group_read(const f_string_static_t path, const bool dereference, uid_t * const group); #endif // _di_f_file_group_read_ /** @@ -760,6 +774,7 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) if access to the file was denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_loop (with error bit) on loop error. * F_memory_not (with error bit) if out of memory. @@ -831,8 +846,8 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_busy (with error bit) if file system is too busy to perform write. * F_buffer (with error bit) if the buffer is invalid. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file aleady exists at the path. * F_file_found_not (with error bit) if a parent path in point does not exist or is a broken symlink. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. @@ -912,8 +927,8 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_buffer (with error bit) if the buffer is invalid. * F_busy (with error bit) if file system is too busy to perform write. + * F_directory_descriptor (with error bit) when either at_id_target or at_id_point is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file aleady exists at the path. * F_file_found_not (with error bit) if a parent path in point does not exist or is a broken symlink. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. @@ -991,8 +1006,8 @@ extern "C" { * * F_access_denied (with error bit) on access denied. * F_buffer (with error bit) if the buffer is invalid. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found_not (with error bit) if the file at path was not found. * F_input_output (with error bit) on I/O error. * F_loop (with error bit) on loop error. @@ -1131,8 +1146,15 @@ extern "C" { /** * Get the current file mode as an f_file_mode_t. * + * The file mode contains more than the file modes such as read, write, and execute. + * The file mode also returns the file type. + * This means that this function must handle dereferencing as needed even if the file is a symbolic link. + * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks. + * Set to FALSE to operate on the symlink itself. * @param mode * The read file mode. * @@ -1149,10 +1171,11 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * - * @see fstat() + * @see lstat() + * @see stat() */ #ifndef _di_f_file_mode_read_ - extern f_status_t f_file_mode_read(const f_string_static_t path, mode_t * const mode); + extern f_status_t f_file_mode_read(const f_string_static_t path, const bool dereference, mode_t * const mode); #endif // _di_f_file_mode_read_ /** @@ -1170,6 +1193,7 @@ extern "C" { * F_data_not if path.used is 0. * * F_access_denied (with error bit) if access to the file was denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_file_found_not (with error bit) if the file was not found. * F_loop (with error bit) on loop error. @@ -1237,6 +1261,7 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_access_mode (with error bit) if the current user does not have access to assign the file mode. * F_file_found_not (with error bit) if file at path was not found. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_input_output (with error bit) on I/O error. * F_loop (with error bit) on loop error. @@ -1412,6 +1437,9 @@ extern "C" { * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks (often is what is desired). + * Set to FALSE to operate on the symlink itself. * @param owner * The id of the file's owner. * @@ -1428,10 +1456,10 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * - * @see fstat() + * @see stat() */ #ifndef _di_f_file_owner_read_ - extern f_status_t f_file_owner_read(const f_string_static_t path, uid_t * const owner); + extern f_status_t f_file_owner_read(const f_string_static_t path, const bool dereference, uid_t * const owner); #endif // _di_f_file_owner_read_ /** @@ -1580,6 +1608,7 @@ extern "C" { * * F_access_denied (with error bit) on access denied. * F_busy (with error bit) if file is busy. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. * F_file_found_not (with error bit) if file not found. * F_file_type_directory (with error bit) file is a directory (directories cannot be removed via this function). @@ -1670,8 +1699,8 @@ extern "C" { * F_access_denied (with error bit) on access denied. * F_buffer (with error bit) if the buffer is invalid. * F_busy (with error bit) if file system is too busy to perform write. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id or to_id. * F_directory_empty_not (with error bit) if the destination is a non-empty directory. * F_file_found_not (with error bit) if file at path was not found. * F_file_type_directory (with error bit) if destination is a directory but source is not. @@ -1705,7 +1734,7 @@ extern "C" { * The new group id to use. * Set to -1 to not change. * @param dereference - * Set to TRUE to dereferenc symlinks (often is what is desired). + * Set to TRUE to dereference symlinks (often is what is desired). * Set to FALSE to operate on the symlink itself. * * @return @@ -1757,8 +1786,8 @@ extern "C" { * F_access_group (with error bit) if the current user does not have access to assign the specified group. * F_access_owner (with error bit) if the current user does not have access to assign the specified owner. * F_buffer (with error bit) if the buffer is invalid. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found_not (with error bit) if file at path was not found. * F_input_output (with error bit) on I/O error. * F_loop (with error bit) on loop error. @@ -1809,7 +1838,7 @@ extern "C" { * @param path * The path to the file. * @param dereference - * Set to TRUE to dereferenc symlinks (often is what is desired). + * Set to TRUE to dereference symlinks (often is what is desired). * Set to FALSE to operate on the symlink itself. * @param size * This gets set to the size of the file. @@ -1840,7 +1869,7 @@ extern "C" { * @param path * The path to the file. * @param dereference - * Set to TRUE to dereferenc symlinks (often is what is desired). + * Set to TRUE to dereference symlinks (often is what is desired). * Set to FALSE to operate on the symlink itself. * @param size * This gets set to the size of the file. @@ -1849,6 +1878,7 @@ extern "C" { * F_none on success. * * F_access_denied (with error bit) if access to the file was denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_file_found_not (with error bit) if the file was not found. * F_loop (with error bit) on loop error. @@ -1895,7 +1925,7 @@ extern "C" { * @param path * The path to the file. * @param dereference - * Set to TRUE to dereferenc symlinks (often is what is desired). + * Set to TRUE to dereference symlinks (often is what is desired). * Set to FALSE to operate on the symlink itself. * @param stat_file * The statistics read. @@ -1934,6 +1964,7 @@ extern "C" { * F_none on success. * * F_access_denied (with error bit) if access to the file was denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_file_found_not (with error bit) if the file was not found. * F_loop (with error bit) on loop error. @@ -2459,8 +2490,8 @@ extern "C" { * F_buffer (with error bit) if the buffer is invalid. * * F_busy (with error bit) if file system is too busy to perform write. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. - * F_directory_descriptor (with error bit) for bad directory descriptor for at_id. * F_file_found (with error bit) if a file aleady exists at the path (when calling utimensat()). * F_file_open_max (with error bit) when system-wide max open files is reached. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. @@ -2528,6 +2559,7 @@ extern "C" { * F_file_found_not if the path was not found. * * F_access_denied (with error bit) if access to the file was denied. + * F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) on invalid directory. * F_loop (with error bit) on loop error. * F_memory_not (with error bit) if out of memory. diff --git a/level_0/f_file/c/file/common.h b/level_0/f_file/c/file/common.h index fb1402e..4554b4a 100644 --- a/level_0/f_file/c/file/common.h +++ b/level_0/f_file/c/file/common.h @@ -428,6 +428,30 @@ extern "C" { #endif // _di_f_file_mode_ /** + * File flag related to file statistics. + * + * These flags are meant to be bitwise for a uint8_t size type or larger. + * + * The f_file_stat_flag_none_e is expected to be 0, therefore it must be safe to use 0 directly. + * + * f_file_stat_flag_*: + * - none: No flags are set (enables non-exclusive and dereference). + * - exclusive: Require that a file does not already exist. + * - group: Copy the group. + * - owner: Copy the owner. + * - reference: Do not perform dereference. + */ +#ifndef _di_f_file_stat_flags_ + enum { + f_file_stat_flag_none_e = 0, + f_file_stat_flag_exclusive_e = 0x1, + f_file_stat_flag_group_e = 0x2, + f_file_stat_flag_owner_e = 0x4, + f_file_stat_flag_reference_e = 0x8, + }; // enum +#endif // _di_f_file_stat_flags_ + +/** * Provide common file operation strings. * * F_file_operation_*: diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 0bb1ef8..8cb410d 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -64,7 +64,7 @@ extern "C" { memset(buffer, 0, sizeof(f_char_t) * size_block); - while ((size_read = read(file_source.id, buffer, size_block)) > (ssize_t) 0) { + while ((size_read = read(file_source.id, buffer, size_block)) > 0) { size_write = write(file_destination.id, buffer, size_read); @@ -589,38 +589,29 @@ extern "C" { int result = 0; - if (dereference) { - if (uid != -1) { + if (uid != -1) { + if (dereference) { result = chown(path.string, uid, -1); - - if (result < 0 && errno == EPERM) { - return F_status_set_error(F_access_owner); - } + } + else { + result = lchown(path.string, uid, -1); } - if (result == 0 && gid != -1) { - result = chown(path.string, -1, gid); - - if (result < 0 && errno == EPERM) { - return F_status_set_error(F_access_group); - } + if (result < 0 && errno == EPERM) { + return F_status_set_error(F_access_owner); } } - else { - if (uid != -1) { - result = lchown(path.string, uid, -1); - if (result < 0 && errno == EPERM) { - return F_status_set_error(F_access_owner); - } + if (result == 0 && gid != -1) { + if (dereference) { + result = chown(path.string, -1, gid); } - - if (result == 0 && gid != -1) { + else { result = lchown(path.string, -1, gid); + } - if (result < 0 && errno == EPERM) { - return F_status_set_error(F_access_group); - } + if (result < 0 && errno == EPERM) { + return F_status_set_error(F_access_group); } } @@ -726,9 +717,7 @@ extern "C" { #if !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_) f_status_t private_f_file_stat_by_id(const int id, struct stat * const file_stat) { - const int result = fstat(id, file_stat); - - if (result < 0) { + if (fstat(id, file_stat) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EFAULT) return F_status_set_error(F_buffer); if (errno == ELOOP) return F_status_set_error(F_loop); diff --git a/level_0/f_file/data/build/defines b/level_0/f_file/data/build/defines index c665317..4f13080 100644 --- a/level_0/f_file/data/build/defines +++ b/level_0/f_file/data/build/defines @@ -1,2 +1 @@ # fss-0000 - diff --git a/level_0/f_file/data/build/settings-mocks b/level_0/f_file/data/build/settings-mocks index 27e594e..51a03da 100644 --- a/level_0/f_file/data/build/settings-mocks +++ b/level_0/f_file/data/build/settings-mocks @@ -67,6 +67,7 @@ flags -Wl,--wrap=fchmodat flags -Wl,--wrap=fchownat flags -Wl,--wrap=feof flags -Wl,--wrap=ferror +flags -Wl,--wrap=fileno flags -Wl,--wrap=flockfile flags -Wl,--wrap=fread_unlocked flags -Wl,--wrap=fstat diff --git a/level_0/f_file/tests/unit/c/mock-file.c b/level_0/f_file/tests/unit/c/mock-file.c index 8562467..6045cbf 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -147,6 +147,10 @@ int __wrap_ferror_unlocked(FILE *stream) { return mock_type(int); } +int __wrap_fileno(FILE *stream) { + return mock_type(int); +} + void __wrap_flockfile(FILE *filehandle) { } diff --git a/level_0/f_file/tests/unit/c/mock-file.h b/level_0/f_file/tests/unit/c/mock-file.h index 92aa74f..744f14b 100644 --- a/level_0/f_file/tests/unit/c/mock-file.h +++ b/level_0/f_file/tests/unit/c/mock-file.h @@ -39,6 +39,7 @@ extern int __wrap_fchown(int fd, uid_t owner, gid_t group); extern int __wrap_fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags); extern int __wrap_feof_unlocked(FILE *stream); extern int __wrap_ferror_unlocked(FILE *stream); +extern int __wrap_fileno(FILE *stream); extern void __wrap_flockfile(FILE *filehandle); extern size_t __wrap_fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream); extern int __wrap_fstat(int fd, struct stat *statbuf); diff --git a/level_0/f_file/tests/unit/c/test-file-clone.c b/level_0/f_file/tests/unit/c/test-file-clone.c index b02b90f..f1dd434 100644 --- a/level_0/f_file/tests/unit/c/test-file-clone.c +++ b/level_0/f_file/tests/unit/c/test-file-clone.c @@ -12,7 +12,7 @@ void test__f_file_clone__fails_during_read_write(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -20,9 +20,9 @@ void test__f_file_clone__fails_during_read_write(void **state) { memset(buffer, 0, sizeof(f_char_t)); - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -61,7 +61,7 @@ void test__f_file_clone__fails_during_read_write(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), F_file_write); } @@ -116,7 +116,7 @@ void test__f_file_clone__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; @@ -126,9 +126,9 @@ void test__f_file_clone__fails_for_link(void **state) { for (int i = 0; i < 18; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_symlink, true); will_return(__wrap_symlink, errnos[i]); @@ -138,7 +138,7 @@ void test__f_file_clone__fails_for_link(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -180,7 +180,7 @@ void test__f_file_clone__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; @@ -190,9 +190,9 @@ void test__f_file_clone__fails_for_link(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_symlink, false); will_return(__wrap_symlink, 0); @@ -200,7 +200,7 @@ void test__f_file_clone__fails_for_link(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -237,7 +237,7 @@ void test__f_file_clone__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; statistics.st_uid = 1; @@ -262,7 +262,7 @@ void test__f_file_clone__fails_for_link(void **state) { will_return(__wrap_lchown, true); will_return(__wrap_lchown, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_true, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_reference_e | f_file_stat_flag_group_e | f_file_stat_flag_owner_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -299,7 +299,7 @@ void test__f_file_clone__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; statistics.st_uid = 1; @@ -327,7 +327,7 @@ void test__f_file_clone__fails_for_link(void **state) { will_return(__wrap_lchown, true); will_return(__wrap_lchown, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_true, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_reference_e | f_file_stat_flag_group_e | f_file_stat_flag_owner_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -359,7 +359,7 @@ void test__f_file_clone__fails_for_other(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); f_char_t buffer[1]; @@ -369,11 +369,11 @@ void test__f_file_clone__fails_for_other(void **state) { statistics.st_mode = 1 | types[i]; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_true); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_exclusive_e); assert_int_equal(F_status_set_fine(status), F_supported_not); } // for @@ -411,10 +411,10 @@ void test__f_file_clone__fails_for_regular(void **state) { for (int i = 0; i < 9; ++i) { - will_return(__wrap_lstat, true); - will_return(__wrap_lstat, errnos[i]); + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -471,20 +471,20 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 21; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, true); will_return(__wrap_open, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -511,15 +511,15 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 6; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -527,7 +527,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_fsync, true); will_return(__wrap_fsync, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -554,15 +554,15 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 6; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -573,7 +573,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_close, true); will_return(__wrap_close, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -610,15 +610,15 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -632,7 +632,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -669,7 +669,7 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -694,7 +694,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_lchown, true); will_return(__wrap_lchown, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_true, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_reference_e | f_file_stat_flag_owner_e | f_file_stat_flag_group_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -731,7 +731,7 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -759,7 +759,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_lchown, true); will_return(__wrap_lchown, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_true, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_reference_e | f_file_stat_flag_owner_e | f_file_stat_flag_group_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -816,15 +816,15 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -841,7 +841,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_open, true); will_return(__wrap_open, errnos[i]); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -898,15 +898,15 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -933,7 +933,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -966,7 +966,7 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -976,9 +976,9 @@ void test__f_file_clone__fails_for_regular(void **state) { for (int i = 0; i < 9; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1014,7 +1014,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1057,7 +1057,7 @@ void test__f_file_clone__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -1067,9 +1067,9 @@ void test__f_file_clone__fails_for_regular(void **state) { for (int i = 0; i < 14; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1109,7 +1109,7 @@ void test__f_file_clone__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_true); + const f_status_t status = f_file_clone(path, path, 0, f_file_stat_flag_exclusive_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1121,19 +1121,19 @@ void test__f_file_clone__returns_data_not(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - const f_status_t status = f_file_clone(f_string_empty_s, f_string_empty_s, F_false, 0, F_false); + const f_status_t status = f_file_clone(f_string_empty_s, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_clone(path, f_string_empty_s, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, f_string_empty_s, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_clone(f_string_empty_s, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(f_string_empty_s, path, 0, 0); assert_int_equal(status, F_data_not); } @@ -1146,13 +1146,13 @@ void test__f_file_clone__works_for_link(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_symlink, false); will_return(__wrap_symlink, 0); @@ -1160,7 +1160,7 @@ void test__f_file_clone__works_for_link(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(status, F_none); } @@ -1173,7 +1173,7 @@ void test__f_file_clone__works_for_regular(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -1181,9 +1181,9 @@ void test__f_file_clone__works_for_regular(void **state) { memset(buffer, 0, sizeof(f_char_t)); - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1226,7 +1226,7 @@ void test__f_file_clone__works_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_clone(path, path, F_false, 0, F_false); + const f_status_t status = f_file_clone(path, path, 0, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-copy.c b/level_0/f_file/tests/unit/c/test-file-copy.c index 908012d..d468617 100644 --- a/level_0/f_file/tests/unit/c/test-file-copy.c +++ b/level_0/f_file/tests/unit/c/test-file-copy.c @@ -14,7 +14,7 @@ void test__f_file_copy__fails_during_read_write(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -22,9 +22,9 @@ void test__f_file_copy__fails_during_read_write(void **state) { memset(buffer, 0, sizeof(f_char_t)); - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -63,7 +63,7 @@ void test__f_file_copy__fails_during_read_write(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), F_file_write); } @@ -113,15 +113,15 @@ void test__f_file_copy__fails_for_block(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_block_d; for (int i = 0; i < 15; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, true); will_return(__wrap_mknod, errnos[i]); @@ -131,7 +131,7 @@ void test__f_file_copy__fails_for_block(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -173,7 +173,7 @@ void test__f_file_copy__fails_for_block(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_block_d; @@ -183,9 +183,9 @@ void test__f_file_copy__fails_for_block(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -193,7 +193,7 @@ void test__f_file_copy__fails_for_block(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -249,15 +249,15 @@ void test__f_file_copy__fails_for_character(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_character_d; for (int i = 0; i < 15; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, true); will_return(__wrap_mknod, errnos[i]); @@ -267,7 +267,7 @@ void test__f_file_copy__fails_for_character(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -309,7 +309,7 @@ void test__f_file_copy__fails_for_character(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_character_d; @@ -319,9 +319,9 @@ void test__f_file_copy__fails_for_character(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -329,7 +329,7 @@ void test__f_file_copy__fails_for_character(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -385,15 +385,15 @@ void test__f_file_copy__fails_for_directory(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; for (int i = 0; i < 15; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkdir, true); will_return(__wrap_mkdir, errnos[i]); @@ -403,7 +403,7 @@ void test__f_file_copy__fails_for_directory(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -445,7 +445,7 @@ void test__f_file_copy__fails_for_directory(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; @@ -455,9 +455,9 @@ void test__f_file_copy__fails_for_directory(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkdir, false); will_return(__wrap_mkdir, 0); @@ -465,7 +465,7 @@ void test__f_file_copy__fails_for_directory(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -511,15 +511,15 @@ void test__f_file_copy__fails_for_fifo(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_fifo_d; for (int i = 0; i < 10; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkfifo, true); will_return(__wrap_mkfifo, errnos[i]); @@ -529,7 +529,7 @@ void test__f_file_copy__fails_for_fifo(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -571,7 +571,7 @@ void test__f_file_copy__fails_for_fifo(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_fifo_d; @@ -581,9 +581,9 @@ void test__f_file_copy__fails_for_fifo(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkfifo, false); will_return(__wrap_mkfifo, 0); @@ -591,7 +591,7 @@ void test__f_file_copy__fails_for_fifo(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -637,20 +637,20 @@ void test__f_file_copy__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; for (int i = 0; i < 10; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_readlink, true); will_return(__wrap_readlink, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -701,7 +701,7 @@ void test__f_file_copy__fails_for_link(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; @@ -711,9 +711,9 @@ void test__f_file_copy__fails_for_link(void **state) { for (int i = 0; i < 18; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_readlink, false); will_return(__wrap_readlink, (void *) buffer); @@ -722,7 +722,7 @@ void test__f_file_copy__fails_for_link(void **state) { will_return(__wrap_symlink, true); will_return(__wrap_symlink, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -766,10 +766,10 @@ void test__f_file_copy__fails_for_regular(void **state) { for (int i = 0; i < 9; ++i) { - will_return(__wrap_lstat, true); - will_return(__wrap_lstat, errnos[i]); + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -826,20 +826,20 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 21; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, true); will_return(__wrap_open, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -866,15 +866,15 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 6; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -882,7 +882,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_fsync, true); will_return(__wrap_fsync, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -909,15 +909,15 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 6; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -928,7 +928,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_close, true); will_return(__wrap_close, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -965,15 +965,15 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -987,7 +987,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1044,15 +1044,15 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1069,7 +1069,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_open, true); will_return(__wrap_open, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1126,15 +1126,15 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1161,7 +1161,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1194,7 +1194,7 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -1204,9 +1204,9 @@ void test__f_file_copy__fails_for_regular(void **state) { for (int i = 0; i < 9; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1242,7 +1242,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1285,7 +1285,7 @@ void test__f_file_copy__fails_for_regular(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -1295,9 +1295,9 @@ void test__f_file_copy__fails_for_regular(void **state) { for (int i = 0; i < 14; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1337,7 +1337,7 @@ void test__f_file_copy__fails_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_true); + const f_status_t status = f_file_copy(path, path, mode, 0, f_file_stat_flag_exclusive_e); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -1388,15 +1388,15 @@ void test__f_file_copy__fails_for_socket(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_socket_d; for (int i = 0; i < 15; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, true); will_return(__wrap_mknod, errnos[i]); @@ -1406,7 +1406,7 @@ void test__f_file_copy__fails_for_socket(void **state) { will_return(__wrap_chmod, 0); } - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -1448,7 +1448,7 @@ void test__f_file_copy__fails_for_socket(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_socket_d; @@ -1458,9 +1458,9 @@ void test__f_file_copy__fails_for_socket(void **state) { for (int i = 0; i < 11; ++i) { - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -1468,7 +1468,7 @@ void test__f_file_copy__fails_for_socket(void **state) { will_return(__wrap_chmod, true); will_return(__wrap_chmod, errnos[i]); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); if (statuss[i] == F_file_found) { assert_int_equal(status, F_none); @@ -1486,19 +1486,19 @@ void test__f_file_copy__returns_data_not(void **state) { const f_mode_t mode = f_mode_t_initialize; { - const f_status_t status = f_file_copy(f_string_empty_s, f_string_empty_s, mode, 0, F_false); + const f_status_t status = f_file_copy(f_string_empty_s, f_string_empty_s, mode, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_copy(path, f_string_empty_s, mode, 0, F_false); + const f_status_t status = f_file_copy(path, f_string_empty_s, mode, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_copy(f_string_empty_s, path, mode, 0, F_false); + const f_status_t status = f_file_copy(f_string_empty_s, path, mode, 0, 0); assert_int_equal(status, F_data_not); } @@ -1512,13 +1512,13 @@ void test__f_file_copy__works_for_block(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_block_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -1526,7 +1526,7 @@ void test__f_file_copy__works_for_block(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1540,13 +1540,13 @@ void test__f_file_copy__works_for_character(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_character_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -1554,7 +1554,7 @@ void test__f_file_copy__works_for_character(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1568,13 +1568,13 @@ void test__f_file_copy__works_for_directory(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkdir, false); will_return(__wrap_mkdir, 0); @@ -1582,7 +1582,7 @@ void test__f_file_copy__works_for_directory(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1596,13 +1596,13 @@ void test__f_file_copy__works_for_fifo(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_fifo_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mkfifo, false); will_return(__wrap_mkfifo, 0); @@ -1610,7 +1610,7 @@ void test__f_file_copy__works_for_fifo(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1624,7 +1624,7 @@ void test__f_file_copy__works_for_link(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_link_d; @@ -1632,9 +1632,9 @@ void test__f_file_copy__works_for_link(void **state) { memset(buffer, 0, sizeof(f_char_t)); - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_readlink, false); will_return(__wrap_readlink, (void *) buffer); @@ -1643,7 +1643,7 @@ void test__f_file_copy__works_for_link(void **state) { will_return(__wrap_symlink, false); will_return(__wrap_symlink, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1657,7 +1657,7 @@ void test__f_file_copy__works_for_regular(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_regular_d; @@ -1665,9 +1665,9 @@ void test__f_file_copy__works_for_regular(void **state) { memset(buffer, 0, sizeof(f_char_t)); - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_open, false); will_return(__wrap_open, 0); @@ -1710,7 +1710,7 @@ void test__f_file_copy__works_for_regular(void **state) { will_return(__wrap_close, false); will_return(__wrap_close, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } @@ -1724,13 +1724,13 @@ void test__f_file_copy__works_for_socket(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_socket_d; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); will_return(__wrap_mknod, false); will_return(__wrap_mknod, 0); @@ -1738,7 +1738,7 @@ void test__f_file_copy__works_for_socket(void **state) { will_return(__wrap_chmod, false); will_return(__wrap_chmod, 0); - const f_status_t status = f_file_copy(path, path, mode, 0, F_false); + const f_status_t status = f_file_copy(path, path, mode, 0, 0); assert_int_equal(status, F_none); } diff --git a/level_0/f_file/tests/unit/c/test-file-descriptor.c b/level_0/f_file/tests/unit/c/test-file-descriptor.c index fa9a021..e92f4f6 100644 --- a/level_0/f_file/tests/unit/c/test-file-descriptor.c +++ b/level_0/f_file/tests/unit/c/test-file-descriptor.c @@ -7,23 +7,15 @@ extern "C" { void test__f_file_descriptor__fails(void **state) { - int errnos[] = { - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_failure, - }; - - for (int i = 0; i < 1; ++i) { + { + f_file_t file = f_file_t_initialize; - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fileno, -1); - //const f_status_t status = f_file_descriptor(path, F_false, &id); + const f_status_t status = f_file_descriptor(&file); - //assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for + assert_int_equal(F_status_set_fine(status), F_stream_not); + } } #ifndef _di_level_0_parameter_checking_ @@ -37,25 +29,18 @@ void test__f_file_descriptor__fails(void **state) { } #endif // _di_level_0_parameter_checking_ -void test__f_file_descriptor__returns_data_not(void **state) { - - { - //const f_status_t status = f_file_descriptor(f_string_empty_s); - - //assert_int_equal(status, F_data_not); - } -} - void test__f_file_descriptor__works(void **state) { { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + const int id = 1; + f_file_t file = f_file_t_initialize; + + will_return(__wrap_fileno, id); - //const f_status_t status = f_file_descriptor(); + const f_status_t status = f_file_descriptor(&file); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(file.id, id); } } diff --git a/level_0/f_file/tests/unit/c/test-file-descriptor.h b/level_0/f_file/tests/unit/c/test-file-descriptor.h index c233ffe..09e9a74 100644 --- a/level_0/f_file/tests/unit/c/test-file-descriptor.h +++ b/level_0/f_file/tests/unit/c/test-file-descriptor.h @@ -27,13 +27,6 @@ extern void test__f_file_descriptor__fails(void **state); #endif // _di_level_0_parameter_checking_ /** - * Test that function works but the path is empty. - * - * @see f_file_descriptor() - */ -extern void test__f_file_descriptor__returns_data_not(void **state); - -/** * Test that function works. * * @see f_file_descriptor() diff --git a/level_0/f_file/tests/unit/c/test-file-exists.c b/level_0/f_file/tests/unit/c/test-file-exists.c index 83b58de..52ca779 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists.c +++ b/level_0/f_file/tests/unit/c/test-file-exists.c @@ -26,19 +26,29 @@ void test__f_file_exists__fails(void **state) { F_buffer, F_loop, F_name, - F_file_found_not, - F_memory_not, F_false, + F_memory_not, + F_directory_not, F_number_overflow, F_file_stat, }; for (int i = 0; i < 9; ++i) { + will_return(__wrap_lstat, true); + will_return(__wrap_lstat, errnos[i]); + + const f_status_t status = f_file_exists(path, F_false); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + for (int i = 0; i < 9; ++i) { + will_return(__wrap_stat, true); will_return(__wrap_stat, errnos[i]); - const f_status_t status = f_file_exists(path); + const f_status_t status = f_file_exists(path, F_true); assert_int_equal(F_status_set_fine(status), statuss[i]); } // for @@ -47,47 +57,40 @@ void test__f_file_exists__fails(void **state) { void test__f_file_exists__returns_data_not(void **state) { { - const f_status_t status = f_file_exists(f_string_empty_s); + const f_status_t status = f_file_exists(f_string_empty_s, F_true); assert_int_equal(status, F_data_not); } } -void test__f_file_exists__returns_false(void **state) { +void test__f_file_exists__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { - will_return(__wrap_stat, false); - will_return(__wrap_stat, &statistics); - will_return(__wrap_stat, 0); + statistics.st_mode = 1 | F_file_type_link_d; - const f_status_t status = f_file_exists(path); + will_return(__wrap_lstat, false); + will_return(__wrap_lstat, &statistics); + will_return(__wrap_lstat, 0); - assert_int_equal(status, F_false); - } -} - -void test__f_file_exists__returns_true(void **state) { + const f_status_t status = f_file_exists(path, F_false); - const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - - struct stat statistics; - - memset(&statistics, 0, sizeof (struct stat)); - - statistics.st_mode = 1 | F_file_type_directory_d; + assert_int_equal(status, F_true); + } { + statistics.st_mode = 1 | F_file_type_regular_d; + will_return(__wrap_stat, false); will_return(__wrap_stat, &statistics); will_return(__wrap_stat, 0); - const f_status_t status = f_file_exists(path); + const f_status_t status = f_file_exists(path, F_true); assert_int_equal(status, F_true); } diff --git a/level_0/f_file/tests/unit/c/test-file-exists.h b/level_0/f_file/tests/unit/c/test-file-exists.h index fdf6ffe..b7c065d 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists.h +++ b/level_0/f_file/tests/unit/c/test-file-exists.h @@ -25,17 +25,10 @@ extern void test__f_file_exists__fails(void **state); extern void test__f_file_exists__returns_data_not(void **state); /** - * Test that function works and returns F_false. + * Test that function works. * * @see f_file_exists() */ -extern void test__f_file_exists__returns_false(void **state); - -/** - * Test that function works and returns F_true. - * - * @see f_file_exists() - */ -extern void test__f_file_exists__returns_true(void **state); +extern void test__f_file_exists__works(void **state); #endif // _TEST__F_file_exists_h diff --git a/level_0/f_file/tests/unit/c/test-file-exists_at.c b/level_0/f_file/tests/unit/c/test-file-exists_at.c index e37a868..6650e6a 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists_at.c +++ b/level_0/f_file/tests/unit/c/test-file-exists_at.c @@ -24,13 +24,13 @@ void test__f_file_exists_at__fails(void **state) { f_status_t statuss[] = { F_access_denied, - F_file_descriptor, + F_directory_descriptor, F_buffer, F_loop, F_name, - F_file_found_not, - F_memory_not, F_false, + F_memory_not, + F_directory_not, F_number_overflow, F_file_stat, }; @@ -55,34 +55,15 @@ void test__f_file_exists_at__returns_data_not(void **state) { } } -void test__f_file_exists_at__returns_false(void **state) { - - const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - - struct stat statistics; - - memset(&statistics, 0, sizeof (struct stat)); - - { - will_return(__wrap_fstatat, false); - will_return(__wrap_fstatat, &statistics); - will_return(__wrap_fstatat, 0); - - const f_status_t status = f_file_exists_at(0, path, 0); - - assert_int_equal(status, F_false); - } -} - -void test__f_file_exists_at__returns_true(void **state) { +void test__f_file_exists_at__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = 1 | F_file_type_directory_d; + statistics.st_mode = 1 | F_file_type_regular_d; { will_return(__wrap_fstatat, false); diff --git a/level_0/f_file/tests/unit/c/test-file-exists_at.h b/level_0/f_file/tests/unit/c/test-file-exists_at.h index c0e2483..90246b6 100644 --- a/level_0/f_file/tests/unit/c/test-file-exists_at.h +++ b/level_0/f_file/tests/unit/c/test-file-exists_at.h @@ -25,17 +25,10 @@ extern void test__f_file_exists_at__fails(void **state); extern void test__f_file_exists_at__returns_data_not(void **state); /** - * Test that function works and returns F_false. + * Test that function works. * * @see f_file_exists_at() */ -extern void test__f_file_exists_at__returns_false(void **state); - -/** - * Test that function works and returns F_true. - * - * @see f_file_exists_at() - */ -extern void test__f_file_exists_at__returns_true(void **state); +extern void test__f_file_exists_at__works(void **state); #endif // _TEST__F_file_exists_at_h diff --git a/level_0/f_file/tests/unit/c/test-file-flush.c b/level_0/f_file/tests/unit/c/test-file-flush.c index 95ebb5d..73bc941 100644 --- a/level_0/f_file/tests/unit/c/test-file-flush.c +++ b/level_0/f_file/tests/unit/c/test-file-flush.c @@ -8,43 +8,43 @@ extern "C" { void test__f_file_flush__fails(void **state) { int errnos[] = { + EBADF, + EDQUOT, + EIO, + ENOSPC, + EROFS, mock_errno_generic, }; f_status_t statuss[] = { + F_file_descriptor, + F_filesystem_quota_block, + F_input_output, + F_space_not, + F_supported_not, F_failure, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 6; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + will_return(__wrap_fsync, true); + will_return(__wrap_fsync, errnos[i]); - //const f_status_t status = f_file_flush(path, F_false, &id); + const f_status_t status = f_file_flush(0); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } -void test__f_file_flush__returns_data_not(void **state) { - - { - //const f_status_t status = f_file_flush(f_string_empty_s); - - //assert_int_equal(status, F_data_not); - } -} - void test__f_file_flush__works(void **state) { { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + will_return(__wrap_fsync, false); + will_return(__wrap_fsync, 0); - //const f_status_t status = f_file_flush(); + const f_status_t status = f_file_flush(0); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); } } diff --git a/level_0/f_file/tests/unit/c/test-file-flush.h b/level_0/f_file/tests/unit/c/test-file-flush.h index 082c1a4..fd64cf3 100644 --- a/level_0/f_file/tests/unit/c/test-file-flush.h +++ b/level_0/f_file/tests/unit/c/test-file-flush.h @@ -18,13 +18,6 @@ extern void test__f_file_flush__fails(void **state); /** - * Test that function works but the path is empty. - * - * @see f_file_flush() - */ -extern void test__f_file_flush__returns_data_not(void **state); - -/** * Test that function works. * * @see f_file_flush() diff --git a/level_0/f_file/tests/unit/c/test-file-group_read.c b/level_0/f_file/tests/unit/c/test-file-group_read.c index 01c4d71..72ea0b0 100644 --- a/level_0/f_file/tests/unit/c/test-file-group_read.c +++ b/level_0/f_file/tests/unit/c/test-file-group_read.c @@ -10,21 +10,39 @@ void test__f_file_group_read__fails(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); int errnos[] = { + EACCES, + EFAULT, + ELOOP, + ENAMETOOLONG, + ENOENT, + ENOMEM, + ENOTDIR, + EOVERFLOW, mock_errno_generic, }; f_status_t statuss[] = { - F_failure, + F_access_denied, + F_buffer, + F_loop, + F_name, + F_file_found_not, + F_memory_not, + F_directory_not, + F_number_overflow, + F_file_stat, }; - for (int i = 0; i < 1; ++i) { + for (int i = 0; i < 9; ++i) { - //will_return(__wrap_open, true); - //will_return(__wrap_open, errnos[i]); + gid_t id = 0; - //const f_status_t status = f_file_group_read(path, F_false, &id); + will_return(__wrap_stat, true); + will_return(__wrap_stat, errnos[i]); - //assert_int_equal(F_status_set_fine(status), statuss[i]); + const f_status_t status = f_file_group_read(path, F_true, &id); + + assert_int_equal(F_status_set_fine(status), statuss[i]); } // for } @@ -32,7 +50,7 @@ void test__f_file_group_read__fails(void **state) { void test__f_file_group_read__parameter_checking(void **state) { { - const f_status_t status = f_file_group_read(f_string_empty_s, 0); + const f_status_t status = f_file_group_read(f_string_empty_s, F_false, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -41,12 +59,12 @@ void test__f_file_group_read__fails(void **state) { void test__f_file_group_read__returns_data_not(void **state) { - const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); - { - //const f_status_t status = f_file_group_read(f_string_empty_s); + gid_t id = 0; + + const f_status_t status = f_file_group_read(f_string_empty_s, F_false, &id); - //assert_int_equal(status, F_data_not); + assert_int_equal(status, F_data_not); } } @@ -55,13 +73,22 @@ void test__f_file_group_read__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - //will_return(__wrap_open, false); - //will_return(__wrap_open, 5); + gid_t id = 0; + + struct stat statistics; + + memset(&statistics, 0, sizeof(struct stat)); + + statistics.st_gid = 5; + + will_return(__wrap_stat, false); + will_return(__wrap_stat, &statistics); + will_return(__wrap_stat, 0); - //const f_status_t status = f_file_group_read(); + const f_status_t status = f_file_group_read(path, F_true, &id); - //assert_int_equal(status, F_none); - //assert_int_equal(id, 5); + assert_int_equal(status, F_none); + assert_int_equal(id, 5); } } diff --git a/level_0/f_file/tests/unit/c/test-file-is.c b/level_0/f_file/tests/unit/c/test-file-is.c index 27d3d17..9ea517d 100644 --- a/level_0/f_file/tests/unit/c/test-file-is.c +++ b/level_0/f_file/tests/unit/c/test-file-is.c @@ -63,7 +63,7 @@ void test__f_file_is__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_stat, false); @@ -83,7 +83,7 @@ void test__f_file_is__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; diff --git a/level_0/f_file/tests/unit/c/test-file-is_at.c b/level_0/f_file/tests/unit/c/test-file-is_at.c index aeb5ab7..9511341 100644 --- a/level_0/f_file/tests/unit/c/test-file-is_at.c +++ b/level_0/f_file/tests/unit/c/test-file-is_at.c @@ -63,7 +63,7 @@ void test__f_file_is_at__returns_false(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); { will_return(__wrap_fstatat, false); @@ -82,7 +82,7 @@ void test__f_file_is_at__returns_true(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; diff --git a/level_0/f_file/tests/unit/c/test-file-mode_read.c b/level_0/f_file/tests/unit/c/test-file-mode_read.c index 341abc5..3c87189 100644 --- a/level_0/f_file/tests/unit/c/test-file-mode_read.c +++ b/level_0/f_file/tests/unit/c/test-file-mode_read.c @@ -30,7 +30,7 @@ void test__f_file_mode_read__fails(void **state) { void test__f_file_mode_read__parameter_checking(void **state) { { - const f_status_t status = f_file_mode_read(f_string_empty_s, 0); + const f_status_t status = f_file_mode_read(f_string_empty_s, F_true, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -42,7 +42,7 @@ void test__f_file_mode_read__returns_data_not(void **state) { { mode_t mode = 0; - const f_status_t status = f_file_mode_read(f_string_empty_s, &mode); + const f_status_t status = f_file_mode_read(f_string_empty_s, F_true, &mode); assert_int_equal(status, F_data_not); } diff --git a/level_0/f_file/tests/unit/c/test-file-owner_read.c b/level_0/f_file/tests/unit/c/test-file-owner_read.c index 45dd70c..0cfc114 100644 --- a/level_0/f_file/tests/unit/c/test-file-owner_read.c +++ b/level_0/f_file/tests/unit/c/test-file-owner_read.c @@ -30,7 +30,7 @@ void test__f_file_owner_read__fails(void **state) { void test__f_file_owner_read__parameter_checking(void **state) { { - const f_status_t status = f_file_owner_read(f_string_empty_s, 0); + const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, 0); assert_int_equal(F_status_set_fine(status), F_parameter); } @@ -42,7 +42,7 @@ void test__f_file_owner_read__returns_data_not(void **state) { { uid_t id = 0; - const f_status_t status = f_file_owner_read(f_string_empty_s, &id); + const f_status_t status = f_file_owner_read(f_string_empty_s, F_false, &id); assert_int_equal(status, F_data_not); } diff --git a/level_0/f_file/tests/unit/c/test-file-touch.c b/level_0/f_file/tests/unit/c/test-file-touch.c index c84b687..673452e 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch.c +++ b/level_0/f_file/tests/unit/c/test-file-touch.c @@ -126,7 +126,7 @@ void test__f_file_touch__fails(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; @@ -163,7 +163,7 @@ void test__f_file_touch__works(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; diff --git a/level_0/f_file/tests/unit/c/test-file-touch_at.c b/level_0/f_file/tests/unit/c/test-file-touch_at.c index 3a7a72e..de78a2a 100644 --- a/level_0/f_file/tests/unit/c/test-file-touch_at.c +++ b/level_0/f_file/tests/unit/c/test-file-touch_at.c @@ -126,7 +126,7 @@ void test__f_file_touch_at__fails(void **state) { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; @@ -163,7 +163,7 @@ void test__f_file_touch_at__works(void **state) { { struct stat statistics; - memset(&statistics, 0, sizeof (struct stat)); + memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = 1 | F_file_type_directory_d; diff --git a/level_0/f_file/tests/unit/c/test-file.c b/level_0/f_file/tests/unit/c/test-file.c index 1a00b1e..cfef2d4 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -95,34 +95,26 @@ int main(void) { cmocka_unit_test(test__f_file_create_node_at__returns_data_not), cmocka_unit_test(test__f_file_create_node_at__returns_supported_not), cmocka_unit_test(test__f_file_create_node_at__works), -/* - cmocka_unit_test(test__f_file_create__fails), - cmocka_unit_test(test__f_file_create__returns_data_not), - cmocka_unit_test(test__f_file_create__works), - - cmocka_unit_test(test__f_file_create_at__fails), - cmocka_unit_test(test__f_file_create_at__returns_data_not), - cmocka_unit_test(test__f_file_create_at__works), - - // f_file_create_device - // f_file_create_device_at - - // f_file_descriptor + cmocka_unit_test(test__f_file_descriptor__fails), + cmocka_unit_test(test__f_file_descriptor__works), cmocka_unit_test(test__f_file_exists__fails), cmocka_unit_test(test__f_file_exists__returns_data_not), - cmocka_unit_test(test__f_file_exists__returns_false), - cmocka_unit_test(test__f_file_exists__returns_true), + cmocka_unit_test(test__f_file_exists__works), cmocka_unit_test(test__f_file_exists_at__fails), cmocka_unit_test(test__f_file_exists_at__returns_data_not), - cmocka_unit_test(test__f_file_exists_at__returns_false), - cmocka_unit_test(test__f_file_exists_at__returns_true), + cmocka_unit_test(test__f_file_exists_at__works), + + cmocka_unit_test(test__f_file_flush__fails), + cmocka_unit_test(test__f_file_flush__works), - // f_file_flush + cmocka_unit_test(test__f_file_group_read__fails), + cmocka_unit_test(test__f_file_group_read__returns_data_not), + cmocka_unit_test(test__f_file_group_read__works), - // f_file_group_read +/* cmocka_unit_test(test__f_file_is__fails), cmocka_unit_test(test__f_file_is__returns_data_not), diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index c5369c0..2176292 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -7,9 +7,6 @@ extern "C" { #ifndef _di_fl_directory_create_ f_status_t fl_directory_create(const f_string_static_t path, const mode_t mode) { - #ifndef _di_level_1_parameter_checking_ - if (!path.string) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ if (!path.used) { return F_data_not; @@ -56,11 +53,7 @@ extern "C" { #endif // _di_fl_directory_create_ #ifndef _di_fl_directory_clone_ - f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse) { - #ifndef _di_level_1_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); - if (!destination.string) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { if (!source.used || !destination.used) { return F_data_not; @@ -75,14 +68,14 @@ extern "C" { memset(&source_stat, 0, sizeof(struct stat)); - status = f_file_stat(source, F_false, &source_stat); + status = f_file_stat(source, !(recurse.flag & f_file_stat_flag_reference_e), &source_stat); if (F_status_is_error(status)) return status; status = f_directory_exists(destination); if (F_status_is_error(status)) return status; if (status == F_true) { - if (recurse.exclusive) { + if (recurse.flag & f_file_stat_flag_exclusive_e) { return F_status_set_error(F_directory_found); } @@ -94,7 +87,7 @@ extern "C" { if (F_status_is_error(status)) return status; } - if (role) { + if (recurse.flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { status = f_file_role_change(destination, source_stat.st_uid, source_stat.st_gid, F_true); if (F_status_is_error(status)) return status; } @@ -124,7 +117,7 @@ extern "C" { } // for if (recurse.depth_max) { - status = private_fl_directory_clone(static_source, static_destination, role, recurse, 1); + status = private_fl_directory_clone(static_source, static_destination, recurse, 1); } } @@ -137,11 +130,7 @@ extern "C" { #endif // _di_fl_directory_clone_ #ifndef _di_fl_directory_clone_content_ - f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse) { - #ifndef _di_level_1_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); - if (!destination.string) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ + f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { if (!source.used || !destination.used) { return F_data_not; @@ -186,7 +175,7 @@ extern "C" { return status; } - status = private_fl_directory_clone(static_source, static_destination, role, recurse, 1); + status = private_fl_directory_clone(static_source, static_destination, recurse, 1); if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { recurse.verbose(recurse.output, source, destination); @@ -198,10 +187,6 @@ extern "C" { #ifndef _di_fl_directory_copy_ f_status_t 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) { - #ifndef _di_level_1_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); - if (!destination.string) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ if (!source.used || !destination.used) { return F_data_not; @@ -216,7 +201,7 @@ extern "C" { if (F_status_is_error(status)) return status; if (status == F_true) { - if (recurse.exclusive) { + if (recurse.flag & f_file_stat_flag_exclusive_e) { return F_status_set_error(F_directory_found); } @@ -268,10 +253,6 @@ extern "C" { #ifndef _di_fl_directory_copy_content_ f_status_t fl_directory_copy_content(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const fl_directory_recurse_t recurse) { - #ifndef _di_level_1_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); - if (!destination.string) return F_status_set_error(F_parameter); - #endif // _di_level_1_parameter_checking_ if (!source.used || !destination.used) { return F_data_not; @@ -327,7 +308,6 @@ extern "C" { #ifndef _di_fl_directory_list_ f_status_t fl_directory_list(const f_string_static_t path, int (*filter)(const struct dirent *), int (*sort)(const struct dirent **, const struct dirent **), const bool dereference, f_directory_listing_t * const listing) { #ifndef _di_level_1_parameter_checking_ - if (!path.string) return F_status_set_error(F_parameter); if (!listing) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -342,7 +322,7 @@ extern "C" { #ifndef _di_fl_directory_path_pop_ f_status_t fl_directory_path_pop(f_string_static_t * const path) { #ifndef _di_level_1_parameter_checking_ - if (!path->string) return F_status_set_error(F_parameter); + if (!path) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ if (!path->used) { @@ -416,7 +396,7 @@ extern "C" { #ifndef _di_fl_directory_path_push_ f_status_t fl_directory_path_push(const f_string_static_t source, f_string_dynamic_t * const destination) { #ifndef _di_level_1_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ if (!source.used) { diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index a95b4e4..4bf4126 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -101,10 +101,6 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param role - * 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 recurse * The directory recurse data. * @@ -124,7 +120,7 @@ extern "C" { * @see f_file_clone() */ #ifndef _di_fl_directory_clone_ - extern f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse); + extern f_status_t fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse); #endif // _di_fl_directory_clone_ /** @@ -145,10 +141,6 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param role - * 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 recurse * The directory recurse data. * @@ -164,7 +156,7 @@ extern "C" { * @see f_file_clone() */ #ifndef _di_fl_directory_clone_content_ - extern f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const bool role, const fl_directory_recurse_t recurse); + extern f_status_t fl_directory_clone_content(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse); #endif // _di_fl_directory_clone_content_ /** @@ -192,7 +184,7 @@ extern "C" { * F_none on success. * F_data_not if source.used or destination.used is 0. * - * F_directory_found (with error bit) if the destination directory is found and recurse.exclusive is TRUE. + * F_directory_found (with error bit) if the destination directory is found and recurse.flag has f_file_stat_flag_exclusive_e. * F_directory_not (with error bit) if the source directory does not exist. * F_failure (with error bit) for any other failure, failures might be populated with individual status codes. * diff --git a/level_1/fl_directory/c/directory/common.h b/level_1/fl_directory/c/directory/common.h index e2b1589..5bc41ed 100644 --- a/level_1/fl_directory/c/directory/common.h +++ b/level_1/fl_directory/c/directory/common.h @@ -26,9 +26,17 @@ extern "C" { * 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). + * flag: + * If f_file_stat_flag_exclusive_e, will fail when file already exists. + * If not f_file_stat_flag_exclusive_e, will not fail if file already exists (existing file will be replaced). + * + * If f_file_stat_flag_reference_e, will operate directly on a link rather than what it references. + * If not f_file_stat_flag_reference_e, will dereference any links. + * + * For clone operations: + * - If f_file_stat_flag_group_e or f_file_stat_flag_owner_e, will copy the owner and group ids. + * - If neither f_file_stat_flag_group_e nor f_file_stat_flag_owner_e, will not copy the owner and group ids. + * (In both cases for a clone operation, the file mode is copied.) * output: * Set to -1 to not print on successful operation. * Set to a valid file descriptor to print to on successful operation. @@ -50,7 +58,7 @@ extern "C" { f_number_unsigned_t depth_max; f_number_unsigned_t size_block; - bool exclusive; + uint8_t flag; f_file_t output; void (*verbose)(const f_file_t, const f_string_static_t, const f_string_static_t); @@ -58,12 +66,12 @@ extern "C" { f_directory_statuss_t *failures; } fl_directory_recurse_t; - #define fl_directory_recurse_t_initialize { FL_directory_recurse_depth_max_d, F_file_default_read_size_d, F_false, macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), 0, 0 } + #define fl_directory_recurse_t_initialize { FL_directory_recurse_depth_max_d, F_file_default_read_size_d, 0, macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), 0, 0 } - #define macro_fl_directory_recurse_t_initialize(depth_max, size_block, exclusive, output, verbose, failures) { \ + #define macro_fl_directory_recurse_t_initialize(depth_max, size_block, flag, output, verbose, failures) { \ depth_max, \ size_block, \ - exclusive, \ + flag, \ output, \ verbose, \ failures \ diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index f53815f..f7b3eff 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_status_t 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 private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, 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; @@ -40,7 +40,7 @@ extern "C" { 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[j], source, destination, role, recurse); + status = private_fl_directory_clone_file(list[i]->array[j], source, destination, recurse); } // for f_string_dynamics_resize(0, list[i]); @@ -97,7 +97,7 @@ extern "C" { if (F_status_is_error(status)) break; if (status == F_true) { - if (recurse.exclusive) { + if (recurse.flag & f_file_stat_flag_exclusive_e) { status = F_status_set_error(F_directory_found); break; @@ -111,14 +111,14 @@ extern "C" { if (F_status_is_error(status)) break; } - if (role) { + if (recurse.flag & (f_file_stat_flag_group_e | f_file_stat_flag_owner_e)) { status = f_file_role_change(destination_sub, source_stat.st_uid, source_stat.st_gid, F_true); if (F_status_is_error(status)) break; } } if (depth < recurse.depth_max) { - status = private_fl_directory_clone(source_sub, destination_sub, role, recurse, depth + 1); + status = private_fl_directory_clone(source_sub, destination_sub, recurse, depth + 1); if (status == F_none && (!recurse.output.stream || recurse.output.id != -1) && recurse.verbose) { recurse.verbose(recurse.output, source_sub, destination_sub); @@ -138,7 +138,7 @@ extern "C" { #endif // !defined(_di_fl_directory_clone_) #if !defined(_di_fl_directory_clone_file_) - f_status_t 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_status_t private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { f_string_static_t path_source = f_string_static_t_initialize; f_string_static_t path_destination = f_string_static_t_initialize; @@ -162,7 +162,7 @@ extern "C" { path_destination_string[destination.used] = f_path_separator_s.string[0]; path_destination_string[destination.used + file.used + 1] = 0; - f_status_t status = f_file_clone(path_source, path_destination, role, recurse.size_block, recurse.exclusive); + f_status_t status = f_file_clone(path_source, path_destination, recurse.size_block, recurse.flag); if (F_status_is_error(status) || status == F_supported_not) { if (status == F_status_set_error(F_memory_not)) { @@ -314,7 +314,7 @@ extern "C" { if (F_status_is_error(status)) break; if (status == F_true) { - if (recurse.exclusive) { + if (recurse.flag & f_file_stat_flag_exclusive_e) { status = F_status_set_error(F_directory_found); break; @@ -374,7 +374,7 @@ extern "C" { path_destination_string[destination.used] = f_path_separator_s.string[0]; path_destination_string[destination.used + file.used + 1] = 0; - f_status_t status = f_file_copy(path_source, path_destination, mode, recurse.size_block, recurse.exclusive); + f_status_t status = f_file_copy(path_source, path_destination, mode, recurse.size_block, recurse.flag); if (F_status_is_error(status) || status == F_supported_not) { if (status == F_status_set_error(F_memory_not)) { diff --git a/level_1/fl_directory/c/private-directory.h b/level_1/fl_directory/c/private-directory.h index 53f8067..3492cf4 100644 --- a/level_1/fl_directory/c/private-directory.h +++ b/level_1/fl_directory/c/private-directory.h @@ -25,10 +25,6 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param role - * 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 recurse * The directory recurse data. * @param depth @@ -42,7 +38,7 @@ extern "C" { * @see fl_directory_clone() */ #if !defined(_di_fl_directory_clone_) - extern f_status_t 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_attribute_visibility_internal_d; + extern f_status_t private_fl_directory_clone(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse, const f_number_unsigned_t depth) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_directory_clone_) /** @@ -59,10 +55,6 @@ extern "C" { * @param destination * The destination file path. * Must be NULL terminated. - * @param role - * 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 recurse * The directory recurse data. * @@ -75,7 +67,7 @@ extern "C" { * @see fl_directory_clone() */ #if !defined(_di_fl_directory_clone_file_) - extern f_status_t 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_attribute_visibility_internal_d; + extern f_status_t private_fl_directory_clone_file(const f_string_static_t file, const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) F_attribute_visibility_internal_d; #endif // !defined(_di_fl_directory_clone_file_) /** diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index b9b9427..a4fbdaa 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -111,7 +111,7 @@ extern "C" { f_status_t status = F_none; if (last_slash) { - status = f_file_exists(program.used ? program : arguments.array[0]); + status = f_file_exists(program.used ? program : arguments.array[0], F_true); if (status != F_true) { return F_status_set_error(F_file_found_not); @@ -149,7 +149,7 @@ extern "C" { status = f_string_dynamic_append(program_name, &paths.array[i]); if (F_status_is_error_not(status)) { - status = f_file_exists(paths.array[i]); + status = f_file_exists(paths.array[i], F_true); if (status == F_true) { found = &paths.array[i]; @@ -301,7 +301,7 @@ extern "C" { f_status_t status = F_none; if (last_slash) { - status = f_file_exists(program.used ? program : arguments.array[0]); + status = f_file_exists(program.used ? program : arguments.array[0], F_true); if (status != F_true) { f_string_dynamics_resize(0, &paths); @@ -341,7 +341,7 @@ extern "C" { status = f_string_dynamic_append(program_name, &paths.array[i]); if (F_status_is_error_not(status)) { - status = f_file_exists(paths.array[i]); + status = f_file_exists(paths.array[i], F_true); if (status == F_true) { found = &paths.array[i]; diff --git a/level_2/fll_file/c/file.c b/level_2/fll_file/c/file.c index 1a5486e..8d0320c 100644 --- a/level_2/fll_file/c/file.c +++ b/level_2/fll_file/c/file.c @@ -6,27 +6,20 @@ extern "C" { #endif #ifndef _di_fll_file_mode_set_all_ - f_status_t fll_file_mode_set_all(const f_string_static_t path, const mode_t mode, const f_number_unsigned_t depth_max) { - #ifndef _di_level_2_parameter_checking_ - if (!path.string) return F_status_set_error(F_parameter); - #endif // _di_level_2_parameter_checking_ + f_status_t fll_file_mode_set_all(const f_string_static_t path, const bool dereference, const mode_t mode, const f_number_unsigned_t depth_max) { if (!path.used) { return F_data_not; } - return private_fll_file_mode_set_all(path, mode, depth_max, 0); + return private_fll_file_mode_set_all(path, dereference, mode, depth_max, 0); } #endif // _di_fll_file_mode_set_all_ #ifndef _di_fll_file_move_ f_status_t fll_file_move(const f_string_static_t source, const f_string_static_t destination, const fl_directory_recurse_t recurse) { - #ifndef _di_level_2_parameter_checking_ - if (!source.string) return F_status_set_error(F_parameter); - if (!destination.string) return F_status_set_error(F_parameter); - #endif // _di_level_2_parameter_checking_ - if (!source.used || !destination.string) { + if (!source.used || !destination.used) { return F_data_not; } @@ -40,7 +33,7 @@ extern "C" { return status; } - status = f_file_is(source, F_file_type_directory_d, F_false); + status = f_file_is(source, F_file_type_directory_d, !(recurse.flag & f_file_stat_flag_reference_e)); if (status == F_file_found_not) { return F_status_set_error(status); @@ -51,7 +44,7 @@ extern "C" { } if (status == F_true) { - status = fl_directory_clone(source, destination, F_true, recurse); + status = fl_directory_clone(source, destination, recurse); if (F_status_is_error(status)) return status; status = f_directory_remove(source, recurse.depth_max, F_false); @@ -61,7 +54,7 @@ extern "C" { } } else { - status = f_file_clone(source, destination, F_true, recurse.size_block, recurse.exclusive); + status = f_file_clone(source, destination, recurse.size_block, recurse.flag); if (F_status_is_error(status)) return status; status = f_file_remove(source); @@ -78,7 +71,6 @@ extern "C" { #ifndef _di_fll_file_role_change_all_ f_status_t fll_file_role_change_all(const f_string_static_t path, const uid_t uid, const gid_t gid, const bool dereference, const f_number_unsigned_t depth_max) { #ifndef _di_level_2_parameter_checking_ - if (!path.string) return F_status_set_error(F_parameter); if (uid == -1 && gid == -1) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ diff --git a/level_2/fll_file/c/file.h b/level_2/fll_file/c/file.h index 305784b..ff98b8c 100644 --- a/level_2/fll_file/c/file.h +++ b/level_2/fll_file/c/file.h @@ -40,6 +40,9 @@ extern "C" { * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks (often is what is desired). + * Set to FALSE to operate on the symlink itself. * @param mode * The new mode to use. * @param depth_max @@ -66,7 +69,7 @@ extern "C" { * Errors (with error bit) from: fl_directory_list(). */ #ifndef _di_fll_file_mode_set_all_ - extern f_status_t fll_file_mode_set_all(const f_string_static_t path, const mode_t mode, const f_number_unsigned_t depth_max); + extern f_status_t fll_file_mode_set_all(const f_string_static_t path, const bool dereference, const mode_t mode, const f_number_unsigned_t depth_max); #endif // _di_fll_file_mode_set_all_ /** diff --git a/level_2/fll_file/c/private-file.c b/level_2/fll_file/c/private-file.c index b051a11..2b627af 100644 --- a/level_2/fll_file/c/private-file.c +++ b/level_2/fll_file/c/private-file.c @@ -6,7 +6,7 @@ extern "C" { #endif #if !defined(_di_fll_file_mode_set_all_) - f_status_t private_fll_file_mode_set_all(const f_string_static_t path, const mode_t mode, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) { + f_status_t private_fll_file_mode_set_all(const f_string_static_t path, const bool dereference, const mode_t mode, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) { f_status_t status = F_none; @@ -19,7 +19,7 @@ extern "C" { f_directory_listing_t listing = f_directory_listing_t_initialize; - status = fl_directory_list(path, 0, 0, F_false, &listing); + status = fl_directory_list(path, 0, 0, dereference, &listing); if (F_status_is_error(status)) { macro_f_directory_listing_t_delete_simple(listing); @@ -93,16 +93,14 @@ extern "C" { } if (depth < depth_max) { - status = private_fll_file_mode_set_all(path_sub, mode, depth_max, depth + 1); + status = private_fll_file_mode_set_all(path_sub, dereference, mode, depth_max, depth + 1); if (F_status_is_error(status)) break; } } // for f_string_dynamics_resize(0, &listing.directory); - if (F_status_is_error(status)) { - return status; - } + if (F_status_is_error(status)) return status; return f_file_mode_set(path, mode); } @@ -110,6 +108,7 @@ extern "C" { #if !defined(_di_fll_file_role_change_all_) f_status_t private_fll_file_role_change_all(const f_string_static_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) { + f_status_t status = F_none; status = f_directory_is(path); @@ -121,7 +120,7 @@ extern "C" { f_directory_listing_t listing = f_directory_listing_t_initialize; - status = fl_directory_list(path, 0, 0, F_false, &listing); + status = fl_directory_list(path, 0, 0, dereference, &listing); if (F_status_is_error(status)) { macro_f_directory_listing_t_delete_simple(listing); diff --git a/level_2/fll_file/c/private-file.h b/level_2/fll_file/c/private-file.h index 0a84958..1e34d7f 100644 --- a/level_2/fll_file/c/private-file.h +++ b/level_2/fll_file/c/private-file.h @@ -22,6 +22,9 @@ extern "C" { * * @param path * The path file name. + * @param dereference + * Set to TRUE to dereference symlinks (often is what is desired). + * Set to FALSE to operate on the symlink itself. * @param mode * The new mode to use. * @param depth_max @@ -46,7 +49,7 @@ extern "C" { * F_failure (with error bit) for any other error. */ #if !defined(_di_fll_file_mode_set_all_) - extern f_status_t private_fll_file_mode_set_all(const f_string_static_t path, const mode_t mode, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) F_attribute_visibility_internal_d; + extern f_status_t private_fll_file_mode_set_all(const f_string_static_t path, const bool dereference, const mode_t mode, const f_number_unsigned_t depth_max, const f_number_unsigned_t depth) F_attribute_visibility_internal_d; #endif // !defined(_di_fll_file_mode_set_all_) /** diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 8430a23..15c56d9 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -431,7 +431,7 @@ extern "C" { for (f_array_length_t counter = 0; counter < main->parameters.remaining.used; ++counter) { - status = f_file_exists(data.argv[main->parameters.remaining.array[counter]]); + status = f_file_exists(data.argv[main->parameters.remaining.array[counter]], F_true); if (status == F_false) { status = F_status_set_error(F_file_found_not); diff --git a/level_3/control/c/private-control.c b/level_3/control/c/private-control.c index 9e3c30f..11c2c65 100644 --- a/level_3/control/c/private-control.c +++ b/level_3/control/c/private-control.c @@ -728,7 +728,7 @@ extern "C" { } } - status = f_file_exists(data->cache.small); + status = f_file_exists(data->cache.small, F_true); if (F_status_is_error(status) || status == F_false) { if (F_status_is_error(status)) { @@ -797,7 +797,7 @@ extern "C" { } // for if (F_status_is_error_not(status)) { - status = f_file_exists(data->cache.small); + status = f_file_exists(data->cache.small, F_true); if (F_status_is_error(status) || status == F_false) { if (F_status_is_error(status)) { diff --git a/level_3/controller/c/controller/private-controller.c b/level_3/controller/c/controller/private-controller.c index 6ed9894..64b8f1a 100644 --- a/level_3/controller/c/controller/private-controller.c +++ b/level_3/controller/c/controller/private-controller.c @@ -143,7 +143,7 @@ extern "C" { f_status_t status = F_none; // The file exists, do not attempt to overwrite. - if (f_file_exists(path) == F_true) { + if (f_file_exists(path, F_true) == F_true) { return F_status_set_error(F_file_found); } @@ -187,7 +187,7 @@ extern "C" { f_status_t controller_file_pid_delete(const pid_t pid, const f_string_static_t path) { // Only delete if the file exists and there is no error while checking. - if (f_file_exists(path) != F_true) { + if (f_file_exists(path, F_true) != F_true) { return F_none; } @@ -238,7 +238,7 @@ extern "C" { *pid = 0; - f_status_t status = f_file_exists(path); + f_status_t status = f_file_exists(path, F_true); if (F_status_is_error(status)) return status; if (status != F_true) { @@ -491,7 +491,7 @@ extern "C" { f_status_t status = F_none; if (global->setting->control.flag & controller_control_flag_readonly_e) { - if (f_file_exists(global->setting->path_control) != F_true) { + if (f_file_exists(global->setting->path_control, F_true) != F_true) { if (global->main->output.verbosity == f_console_verbosity_debug_e) { controller_lock_print(global->main->output.to, global->thread); diff --git a/level_3/controller/c/rule/private-rule.c b/level_3/controller/c/rule/private-rule.c index 738bd37..8ee39d8 100644 --- a/level_3/controller/c/rule/private-rule.c +++ b/level_3/controller/c/rule/private-rule.c @@ -1560,7 +1560,7 @@ extern "C" { } } - status = f_file_exists(pid_file); + status = f_file_exists(pid_file, F_true); if (F_status_is_error(status)) { controller_print_error_file(thread, main->error, F_status_set_fine(status), "f_file_exists", F_true, pid_file, f_file_operation_find_s, fll_error_file_type_file_e); diff --git a/level_3/controller/c/thread/private-thread.c b/level_3/controller/c/thread/private-thread.c index d01d91d..d5b401a 100644 --- a/level_3/controller/c/thread/private-thread.c +++ b/level_3/controller/c/thread/private-thread.c @@ -72,7 +72,7 @@ extern "C" { for (; j < process->path_pids.used; ++j) { - if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j]) == F_true) { + if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j], F_true) == F_true) { break; } } // for @@ -218,7 +218,7 @@ extern "C" { if (main->parameters.array[controller_parameter_daemon_e].result == f_console_result_found_e) { setting->ready = controller_setting_ready_done_e; - if (f_file_exists(setting->path_pid) == F_true) { + if (f_file_exists(setting->path_pid, F_true) == F_true) { if (main->error.verbosity != f_console_verbosity_quiet_e) { controller_lock_print(main->error.to, &thread); diff --git a/level_3/controller/c/thread/private-thread_entry.c b/level_3/controller/c/thread/private-thread_entry.c index ea080c4..ba707b6 100644 --- a/level_3/controller/c/thread/private-thread_entry.c +++ b/level_3/controller/c/thread/private-thread_entry.c @@ -38,7 +38,7 @@ extern "C" { if (F_status_is_error_not(*status) && *status != F_child) { if (main->parameters.array[controller_parameter_validate_e].result == f_console_result_none_e || main->parameters.array[controller_parameter_simulate_e].result == f_console_result_found_e) { - if (entry->setting->entry.pid == controller_entry_pid_require_e && f_file_exists(entry->setting->path_pid) == F_true) { + if (entry->setting->entry.pid == controller_entry_pid_require_e && f_file_exists(entry->setting->path_pid, F_true) == F_true) { if (main->error.verbosity != f_console_verbosity_quiet_e) { controller_lock_print(main->error.to, entry->global->thread); diff --git a/level_3/controller/c/thread/private-thread_process.c b/level_3/controller/c/thread/private-thread_process.c index e57446c..2bf7204 100644 --- a/level_3/controller/c/thread/private-thread_process.c +++ b/level_3/controller/c/thread/private-thread_process.c @@ -126,7 +126,7 @@ extern "C" { for (j = 0; j < process->path_pids.used; ++j) { - if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j]) == F_true) { + if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j], F_true) == F_true) { status = controller_file_pid_read(process->path_pids.array[j], &pid); if (pid) { @@ -173,7 +173,7 @@ extern "C" { for (; spent < controller_thread_exit_process_cancel_total_d; ++spent) { - if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j]) == F_true) { + if (process->path_pids.array[j].used && f_file_exists(process->path_pids.array[j], F_true) == F_true) { status = controller_file_pid_read(process->path_pids.array[j], &pid); if (pid) { @@ -240,7 +240,7 @@ extern "C" { for (j = 0; j < process->path_pids.used; ++j) { - if (f_file_exists(process->path_pids.array[j]) == F_true) { + if (f_file_exists(process->path_pids.array[j], F_true) == F_true) { status = controller_file_pid_read(process->path_pids.array[j], &pid); if (pid) { diff --git a/level_3/fake/c/private-build-library.c b/level_3/fake/c/private-build-library.c index 69b2dae..feba8c0 100644 --- a/level_3/fake/c/private-build-library.c +++ b/level_3/fake/c/private-build-library.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fake_build_library_script_ int fake_build_library_script(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; fake_build_touch(data, file_stage, status); @@ -24,7 +24,7 @@ extern "C" { #ifndef _di_fake_build_library_shared_ int fake_build_library_shared(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_library.used && !data_build->setting.build_sources_library_shared.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { @@ -446,7 +446,7 @@ extern "C" { #ifndef _di_fake_build_library_static_ int fake_build_library_static(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_library.used && !data_build->setting.build_sources_library_static.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/fake/c/private-build-object.c b/level_3/fake/c/private-build-object.c index 6b5ecea..5d8232f 100644 --- a/level_3/fake/c/private-build-object.c +++ b/level_3/fake/c/private-build-object.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fake_build_object_script_ int fake_build_object_script(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; fake_build_touch(data, file_stage, status); @@ -24,7 +24,7 @@ extern "C" { #ifndef _di_fake_build_object_shared_ int fake_build_object_shared(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_object.used && !data_build->setting.build_sources_object_shared.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { @@ -95,7 +95,7 @@ extern "C" { #ifndef _di_fake_build_object_static_ int fake_build_object_static(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_object.used && !data_build->setting.build_sources_object_static.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/fake/c/private-build-objects.c b/level_3/fake/c/private-build-objects.c index 3b7a20f..c66fb70 100644 --- a/level_3/fake/c/private-build-objects.c +++ b/level_3/fake/c/private-build-objects.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fake_build_objects_static_ int fake_build_objects_static(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_library.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/fake/c/private-build-program.c b/level_3/fake/c/private-build-program.c index 40c9ea9..0b1ebb7 100644 --- a/level_3/fake/c/private-build-program.c +++ b/level_3/fake/c/private-build-program.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fake_build_program_script_ int fake_build_program_script(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; fake_build_touch(data, file_stage, status); @@ -24,7 +24,7 @@ extern "C" { #ifndef _di_fake_build_program_shared_ int fake_build_program_shared(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_program.used && !data_build->setting.build_sources_program_shared.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { @@ -118,7 +118,7 @@ extern "C" { #ifndef _di_fake_build_program_static_ int fake_build_program_static(fake_data_t * const data, fake_build_data_t * const data_build, const f_mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!data_build->setting.build_sources_program.used && !data_build->setting.build_sources_program_static.used) return 0; if (data->main->output.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/fake/c/private-build-skeleton.c b/level_3/fake/c/private-build-skeleton.c index 58a6235..0a19285 100644 --- a/level_3/fake/c/private-build-skeleton.c +++ b/level_3/fake/c/private-build-skeleton.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fake_build_skeleton_ void fake_build_skeleton(fake_data_t * const data, fake_build_data_t * const data_build, const mode_t mode, const f_string_static_t file_stage, f_status_t * const status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return; f_string_static_t path_headers = f_string_static_t_initialize; path_headers.used = data->path_build_includes.used + data_build->setting.path_headers.used; diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index 04002d5..422003f 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -346,7 +346,7 @@ extern "C" { #ifndef _di_fake_build_copy_ void fake_build_copy(fake_data_t * const data, const f_mode_t mode, const f_string_static_t label, const f_string_static_t source, const f_string_static_t destination, const f_string_statics_t files, const f_string_static_t file_stage, const f_array_length_t perserve_offset, f_status_t *status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return; if (fll_program_standard_signal_received(data->main)) { fake_print_signal_received(data); @@ -517,7 +517,7 @@ extern "C" { } } - *status = f_file_copy(path_source, destination_file, mode, F_file_default_read_size_d, F_false); + *status = f_file_copy(path_source, destination_file, mode, F_file_default_read_size_d, f_file_stat_flag_reference_e); if (F_status_is_error(*status)) { fake_print_error_build_operation_file(data, F_status_set_fine(*status), "f_file_copy", f_file_operation_copy_s, f_file_operation_to_s, path_source, destination_file, F_true); @@ -553,7 +553,7 @@ extern "C" { #ifndef _di_fake_build_execute_process_script_ int fake_build_execute_process_script(fake_data_t * const data, fake_build_data_t * const data_build, const f_string_static_t process_script, const f_string_static_t file_stage, f_status_t *status) { - if (F_status_is_error(*status) || f_file_exists(file_stage) == F_true || *status == F_child) return data->main->child; + if (F_status_is_error(*status) || f_file_exists(file_stage, F_true) == F_true || *status == F_child) return data->main->child; if (!process_script.used) return 0; f_string_dynamics_t arguments = f_string_dynamics_t_initialize; diff --git a/level_3/fake/c/private-common.c b/level_3/fake/c/private-common.c index 6013987..863e7ca 100644 --- a/level_3/fake/c/private-common.c +++ b/level_3/fake/c/private-common.c @@ -217,6 +217,7 @@ extern "C" { const f_string_static_t fake_make_operation_argument_has_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_has_s, 0, FAKE_make_operation_argument_has_s_length); const f_string_static_t fake_make_operation_argument_ignore_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_ignore_s, 0, FAKE_make_operation_argument_ignore_s_length); const f_string_static_t fake_make_operation_argument_is_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_is_s, 0, FAKE_make_operation_argument_is_s_length); + const f_string_static_t fake_make_operation_argument_no_dereference_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_no_dereference_s, 0, FAKE_make_operation_argument_no_dereference_s_length); const f_string_static_t fake_make_operation_argument_parameter_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_parameter_s, 0, FAKE_make_operation_argument_parameter_s_length); const f_string_static_t fake_make_operation_argument_point_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_point_s, 0, FAKE_make_operation_argument_point_s_length); const f_string_static_t fake_make_operation_argument_recursive_s = macro_f_string_static_t_initialize(FAKE_make_operation_argument_recursive_s, 0, FAKE_make_operation_argument_recursive_s_length); diff --git a/level_3/fake/c/private-common.h b/level_3/fake/c/private-common.h index 01a712b..38ecfdc 100644 --- a/level_3/fake/c/private-common.h +++ b/level_3/fake/c/private-common.h @@ -1199,37 +1199,39 @@ extern "C" { #define fake_make_operation_total_d 34 - #define FAKE_make_operation_argument_environment_s "environment" - #define FAKE_make_operation_argument_failure_s "failure" - #define FAKE_make_operation_argument_file_s "file" - #define FAKE_make_operation_argument_directory_s "directory" - #define FAKE_make_operation_argument_error_s "error" - #define FAKE_make_operation_argument_exit_s "exit" - #define FAKE_make_operation_argument_has_s "has" - #define FAKE_make_operation_argument_ignore_s "ignore" - #define FAKE_make_operation_argument_is_s "is" - #define FAKE_make_operation_argument_parameter_s "parameter" - #define FAKE_make_operation_argument_point_s "point" - #define FAKE_make_operation_argument_recursive_s "recursive" - #define FAKE_make_operation_argument_success_s "success" - #define FAKE_make_operation_argument_target_s "target" - #define FAKE_make_operation_argument_warn_s "warn" - - #define FAKE_make_operation_argument_environment_s_length 11 - #define FAKE_make_operation_argument_failure_s_length 7 - #define FAKE_make_operation_argument_file_s_length 4 - #define FAKE_make_operation_argument_directory_s_length 9 - #define FAKE_make_operation_argument_error_s_length 5 - #define FAKE_make_operation_argument_exit_s_length 4 - #define FAKE_make_operation_argument_has_s_length 3 - #define FAKE_make_operation_argument_ignore_s_length 6 - #define FAKE_make_operation_argument_is_s_length 2 - #define FAKE_make_operation_argument_parameter_s_length 9 - #define FAKE_make_operation_argument_point_s_length 5 - #define FAKE_make_operation_argument_recursive_s_length 9 - #define FAKE_make_operation_argument_success_s_length 7 - #define FAKE_make_operation_argument_target_s_length 6 - #define FAKE_make_operation_argument_warn_s_length 4 + #define FAKE_make_operation_argument_environment_s "environment" + #define FAKE_make_operation_argument_failure_s "failure" + #define FAKE_make_operation_argument_file_s "file" + #define FAKE_make_operation_argument_directory_s "directory" + #define FAKE_make_operation_argument_error_s "error" + #define FAKE_make_operation_argument_exit_s "exit" + #define FAKE_make_operation_argument_has_s "has" + #define FAKE_make_operation_argument_ignore_s "ignore" + #define FAKE_make_operation_argument_is_s "is" + #define FAKE_make_operation_argument_no_dereference_s "no_dereference" + #define FAKE_make_operation_argument_parameter_s "parameter" + #define FAKE_make_operation_argument_point_s "point" + #define FAKE_make_operation_argument_recursive_s "recursive" + #define FAKE_make_operation_argument_success_s "success" + #define FAKE_make_operation_argument_target_s "target" + #define FAKE_make_operation_argument_warn_s "warn" + + #define FAKE_make_operation_argument_environment_s_length 11 + #define FAKE_make_operation_argument_failure_s_length 7 + #define FAKE_make_operation_argument_file_s_length 4 + #define FAKE_make_operation_argument_directory_s_length 9 + #define FAKE_make_operation_argument_error_s_length 5 + #define FAKE_make_operation_argument_exit_s_length 4 + #define FAKE_make_operation_argument_has_s_length 3 + #define FAKE_make_operation_argument_ignore_s_length 6 + #define FAKE_make_operation_argument_is_s_length 2 + #define FAKE_make_operation_argument_no_dereference_s_length 14 + #define FAKE_make_operation_argument_parameter_s_length 9 + #define FAKE_make_operation_argument_point_s_length 5 + #define FAKE_make_operation_argument_recursive_s_length 9 + #define FAKE_make_operation_argument_success_s_length 7 + #define FAKE_make_operation_argument_target_s_length 6 + #define FAKE_make_operation_argument_warn_s_length 4 extern const f_string_static_t fake_make_operation_argument_environment_s; extern const f_string_static_t fake_make_operation_argument_failure_s; @@ -1240,6 +1242,7 @@ extern "C" { extern const f_string_static_t fake_make_operation_argument_has_s; extern const f_string_static_t fake_make_operation_argument_ignore_s; extern const f_string_static_t fake_make_operation_argument_is_s; + extern const f_string_static_t fake_make_operation_argument_no_dereference_s; extern const f_string_static_t fake_make_operation_argument_parameter_s; extern const f_string_static_t fake_make_operation_argument_point_s; extern const f_string_static_t fake_make_operation_argument_recursive_s; diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 43fd7c2..03a28e2 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -103,7 +103,7 @@ extern "C" { return F_status_set_error(F_interrupt); } - status = f_file_exists(path_file); + status = f_file_exists(path_file, F_true); if (status == F_true) { { diff --git a/level_3/fake/c/private-make-operate_process.c b/level_3/fake/c/private-make-operate_process.c index 2e28373..a1f71f2 100644 --- a/level_3/fake/c/private-make-operate_process.c +++ b/level_3/fake/c/private-make-operate_process.c @@ -151,7 +151,6 @@ extern "C" { } if (state_process->operation == fake_make_operation_type_define_e) { - if (arguments.used > 1) { *status = f_environment_set(arguments.array[0], arguments.array[1], F_true); } diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index b2470d9..4f45a3d 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -30,6 +30,8 @@ extern "C" { recurse.output = data_make->main->output.to; recurse.verbose = fake_verbose_print_clone; } + + recurse.flag = f_file_stat_flag_group_e | f_file_stat_flag_owner_e; } else { macro_f_mode_t_set_default_umask(mode, data_make->main->umask); @@ -41,9 +43,15 @@ extern "C" { } bool existing = F_true; + f_array_length_t i = 0; + + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + recurse.flag |= f_file_stat_flag_reference_e; + } // In this case, the destination could be a file, so confirm this. - if (arguments.used == 2) { + if (arguments.used == 2 + i) { status = f_directory_is(arguments.array[1]); if (F_status_is_error(status)) { @@ -57,7 +65,7 @@ extern "C" { } } - for (f_array_length_t i = 0; i < total; ++i) { + for (; i < total; ++i) { destination.used = arguments.array[total].used; @@ -80,7 +88,7 @@ extern "C" { if (status_file == F_true) { if (clone) { - status_file = fl_directory_clone(arguments.array[i], destination, F_true, recurse); + status_file = fl_directory_clone(arguments.array[i], destination, recurse); } else { status_file = fl_directory_copy(arguments.array[i], destination, mode, recurse); @@ -94,10 +102,10 @@ extern "C" { } else if (status_file == F_false) { if (clone) { - status_file = f_file_clone(arguments.array[i], destination, F_true, recurse.size_block, recurse.exclusive); + status_file = f_file_clone(arguments.array[i], destination, recurse.size_block, recurse.flag); } else { - status_file = f_file_copy(arguments.array[i], destination, mode, recurse.size_block, recurse.exclusive); + status_file = f_file_copy(arguments.array[i], destination, mode, recurse.size_block, recurse.flag); } if (F_status_is_error(status_file)) { @@ -271,11 +279,18 @@ extern "C" { f_status_t status_file = F_none; gid_t id = 0; + bool dereference = F_true; + f_array_length_t i = 0; - status = fake_make_get_id_group(data_make->data, data_make->error, arguments.array[0], &id); + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } + + status = fake_make_get_id_group(data_make->data, data_make->error, arguments.array[i++], &id); if (F_status_is_error(status)) return 0; - for (f_array_length_t i = 1; i < arguments.used; ++i) { + for (; i < arguments.used; ++i) { status_file = fake_make_assure_inside_project(data_make, arguments.array[i]); @@ -288,10 +303,10 @@ extern "C" { } if (all) { - status_file = fll_file_role_change_all(arguments.array[i], -1, id, F_false, fake_make_operation_recursion_depth_max_d); + status_file = fll_file_role_change_all(arguments.array[i], -1, id, dereference, fake_make_operation_recursion_depth_max_d); } else { - status_file = f_file_role_change(arguments.array[i], -1, id, F_false); + status_file = f_file_role_change(arguments.array[i], -1, id, dereference); } if (F_status_is_error(status_file)) { @@ -477,12 +492,19 @@ extern "C" { f_status_t fake_make_operate_process_type_if_exists(fake_make_data_t * const data_make, const f_string_dynamics_t arguments, const bool if_not, fake_state_process_t *state_process) { f_status_t status = F_none; + f_array_length_t i = if_not ? 2 : 1; + bool dereference = F_true; state_process->condition_result = fake_condition_result_true_e; - for (f_array_length_t i = if_not ? 2 : 1; i < arguments.used; ++i) { + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } + + for (; i < arguments.used; ++i) { - status = f_file_exists(arguments.array[i]); + status = f_file_exists(arguments.array[i], dereference); if (F_status_is_error(status)) { state_process->condition_result = fake_condition_result_error_e; @@ -526,6 +548,12 @@ extern "C" { uint8_t type = 0; f_array_length_t i = if_not ? 2 : 1; + bool dereference = F_true; + + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } status = F_none; @@ -567,7 +595,7 @@ extern "C" { for (; i < arguments.used; ++i, mode_file = 0) { - status = f_file_mode_read(arguments.array[i], &mode_file); + status = f_file_mode_read(arguments.array[i], dereference, &mode_file); if (F_status_is_error(status)) { state_process->condition_result = fake_condition_result_error_e; @@ -781,17 +809,22 @@ extern "C" { f_status_t status = F_none; uid_t id = 0; + f_array_length_t i = if_not ? 2 : 1; + bool dereference = F_true; - status = fake_make_get_id_group(data_make->data, data_make->error, arguments.array[if_not ? 2 : 1], &id); - if (F_status_is_error(status)) return status; + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } - uid_t id_file = 0; + status = fake_make_get_id_group(data_make->data, data_make->error, arguments.array[i++], &id); + if (F_status_is_error(status)) return status; state_process->condition_result = fake_condition_result_true_e; - for (f_array_length_t i = if_not ? 3 : 2; i < arguments.used; ++i, id_file = 0) { + for (uid_t id_file = 0; i < arguments.used; ++i, id_file = 0) { - status = f_file_group_read(arguments.array[i], &id_file); + status = f_file_group_read(arguments.array[i], dereference, &id_file); if (F_status_is_error(status)) { state_process->condition_result = fake_condition_result_error_e; @@ -863,7 +896,7 @@ extern "C" { for (f_array_length_t i = if_not ? 4 : 3; i < arguments.used; ++i, mode_file = 0) { - status = f_file_mode_read(arguments.array[i], &mode_file); + status = f_file_mode_read(arguments.array[i], F_true, &mode_file); if (F_status_is_error(status)) { state_process->condition_result = fake_condition_result_error_e; @@ -916,17 +949,22 @@ extern "C" { f_status_t status = F_none; uid_t id = 0; + f_array_length_t i = if_not ? 2 : 1; + bool dereference = F_true; - status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[if_not ? 2 : 1], &id); - if (F_status_is_error(status)) return status; + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } - uid_t id_file = 0; + status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[i++], &id); + if (F_status_is_error(status)) return status; state_process->condition_result = fake_condition_result_true_e; - for (f_array_length_t i = if_not ? 3 : 2; i < arguments.used; ++i, id_file = 0) { + for (uid_t id_file = 0; i < arguments.used; ++i, id_file = 0) { - status = f_file_owner_read(arguments.array[i], &id_file); + status = f_file_owner_read(arguments.array[i], dereference, &id_file); if (F_status_is_error(status)) { state_process->condition_result = fake_condition_result_error_e; @@ -974,7 +1012,7 @@ extern "C" { for (f_array_length_t i = 1; i < arguments.used; ++i, mode = 0) { - status = f_file_mode_read(arguments.array[i], &mode_file); + status = f_file_mode_read(arguments.array[i], F_true, &mode_file); if (F_status_is_error(status)) { fll_error_file_print(data_make->error, F_status_set_fine(status), "f_file_mode_read", F_true, arguments.array[i], f_file_operation_change_group_s, fll_error_file_type_file_e); @@ -991,7 +1029,7 @@ extern "C" { } if (all) { - status = fll_file_mode_set_all(arguments.array[i], mode, fake_make_operation_recursion_depth_max_d); + status = fll_file_mode_set_all(arguments.array[i], F_true, mode, fake_make_operation_recursion_depth_max_d); } else { status = f_file_mode_set(arguments.array[i], mode); @@ -1087,13 +1125,20 @@ extern "C" { f_status_t status = F_none; uid_t id = 0; + bool dereference = F_true; + f_array_length_t i = 0; - status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[0], &id); + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + ++i; + dereference = F_false; + } + + status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[i++], &id); if (F_status_is_error(status)) return status; f_status_t status_file = F_none; - for (f_array_length_t i = 1; i < arguments.used; ++i) { + for (; i < arguments.used; ++i) { status_file = fake_make_assure_inside_project(data_make, arguments.array[i]); @@ -1106,10 +1151,10 @@ extern "C" { } if (all) { - status_file = fll_file_role_change_all(arguments.array[i], id, -1, F_false, fake_make_operation_recursion_depth_max_d); + status_file = fll_file_role_change_all(arguments.array[i], id, -1, dereference, fake_make_operation_recursion_depth_max_d); } else { - status_file = f_file_role_change(arguments.array[i], id, -1, F_false); + status_file = f_file_role_change(arguments.array[i], id, -1, dereference); } if (F_status_is_error(status_file)) { diff --git a/level_3/fake/c/private-make-operate_validate.c b/level_3/fake/c/private-make-operate_validate.c index baf49d9..f59f12e 100644 --- a/level_3/fake/c/private-make-operate_validate.c +++ b/level_3/fake/c/private-make-operate_validate.c @@ -171,7 +171,7 @@ extern "C" { for (f_array_length_t i = 0; i < arguments.used - 1; ++i) { - if (f_file_exists(arguments.array[i]) != F_true) { + if (f_file_exists(arguments.array[i], F_true) != F_true) { if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { flockfile(data_make->error.to.stream); @@ -282,7 +282,7 @@ extern "C" { for (f_array_length_t i = 0; i < arguments.used - 1; ++i) { - if (f_file_exists(arguments.array[i]) != F_true) { + if (f_file_exists(arguments.array[i], F_true) != F_true) { if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { flockfile(data_make->error.to.stream); @@ -530,36 +530,46 @@ extern "C" { } if (state_process->operation == fake_make_operation_type_group_e || state_process->operation == fake_make_operation_type_groups_e || state_process->operation == fake_make_operation_type_mode_e || state_process->operation == fake_make_operation_type_modes_e || state_process->operation == fake_make_operation_type_owner_e || state_process->operation == fake_make_operation_type_owners_e) { - if (arguments.used > 1) { - f_status_t status_file = F_none; + if (arguments.used) { + f_array_length_t i = 1; - for (f_array_length_t i = 1; i < arguments.used; ++i) { + if (state_process->operation == fake_make_operation_type_group_e || state_process->operation == fake_make_operation_type_groups_e || state_process->operation == fake_make_operation_type_owner_e || state_process->operation == fake_make_operation_type_owners_e) { + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[i]) == F_equal_to) { + i = 2; + } + } - status_file = f_file_is(arguments.array[i], F_file_type_regular_d, F_false); + if (arguments.used > i) { + f_status_t status_file = F_none; - if (status_file == F_file_found_not) { - if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { - flockfile(data_make->error.to.stream); + for (; i < arguments.used; ++i) { - fl_print_format("%r%[%QFailed to find file '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context); - fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[i], data_make->error.notable); - fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); + status_file = f_file_is(arguments.array[i], F_file_type_regular_d, F_false); - funlockfile(data_make->error.to.stream); - } + if (status_file == F_file_found_not) { + if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { + flockfile(data_make->error.to.stream); - *status = F_status_set_error(status_file); - } - else if (F_status_is_error(status_file)) { - if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { - fll_error_file_print(data_make->error, F_status_set_fine(*status), "f_file_is", F_true, arguments.array[i], f_file_operation_find_s, fll_error_file_type_directory_e); + fl_print_format("%r%[%QFailed to find file '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context); + fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[i], data_make->error.notable); + fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); + + funlockfile(data_make->error.to.stream); + } + + *status = F_status_set_error(status_file); } + else if (F_status_is_error(status_file)) { + if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { + fll_error_file_print(data_make->error, F_status_set_fine(*status), "f_file_is", F_true, arguments.array[i], f_file_operation_find_s, fll_error_file_type_directory_e); + } - *status = status_file; + *status = status_file; + } } - } - return; + return; + } } fake_print_error_requires_more_arguments(data_make); @@ -662,30 +672,6 @@ extern "C" { fake_make_operation_if_type_if_success_e, }; - const uint8_t if_type_minimum[] = { - 3, // If defined. - 2, // If equal (==). - 2, // If equal not (<>). - 2, // If exists. - 1, // If failure. - 2, // If greater (>). - 2, // If greater equal (>=). - 3, // If group. - 3, // If is. - 2, // If less (<). - 2, // If less equal (<=). - 4, // If mode. - 3, // If not. - 5, // If not defined. - 3, // If not exists. - 4, // If not group. - 4, // If not is. - 5, // If not mode. - 4, // If not owner. - 3, // If owner. - 1, // If success. - }; - const f_string_static_t if_not_type_strings[] = { fake_make_operation_argument_if_defined_s, fake_make_operation_argument_if_exists_s, @@ -704,18 +690,11 @@ extern "C" { fake_make_operation_if_type_if_not_owner_e, }; - const uint8_t if_not_type_minimum[] = { - 4, // If not defined. - 3, // If not exists. - 4, // If not group. - 4, // If not is. - 5, // If not mode. - 4, // If not owner. - }; - f_array_length_t i = 0; f_array_length_t j = 0; + f_array_length_t k = 0; f_string_static_t if_and_or; + bool dereference = F_true; if (state_process->operation == fake_make_operation_type_and_e) { if_and_or = fake_make_operation_and_s; @@ -727,12 +706,50 @@ extern "C" { if_and_or = fake_make_operation_if_s; } + if (fl_string_dynamic_compare(fake_make_operation_argument_no_dereference_s, arguments.array[k]) == F_equal_to) { + ++k; + dereference = F_false; + } + + const uint8_t if_type_minimum[] = { + dereference ? 3 : 4, // If defined. + dereference ? 2 : 3, // If equal (==). + dereference ? 2 : 3, // If equal not (<>). + dereference ? 2 : 3, // If exists. + dereference ? 1 : 2, // If failure. + dereference ? 2 : 3, // If greater (>). + dereference ? 2 : 3, // If greater equal (>=). + dereference ? 3 : 4, // If group. + dereference ? 3 : 4, // If is. + dereference ? 2 : 3, // If less (<). + dereference ? 2 : 3, // If less equal (<=). + dereference ? 4 : 5, // If mode. + dereference ? 3 : 4, // If not. + dereference ? 5 : 6, // If not defined. + dereference ? 3 : 4, // If not exists. + dereference ? 4 : 5, // If not group. + dereference ? 4 : 5, // If not is. + dereference ? 5 : 6, // If not mode. + dereference ? 4 : 5, // If not owner. + dereference ? 3 : 4, // If owner. + dereference ? 1 : 2, // If success. + }; + + const uint8_t if_not_type_minimum[] = { + dereference ? 4 : 5, // If not defined. + dereference ? 3 : 4, // If not exists. + dereference ? 4 : 5, // If not group. + dereference ? 4 : 5, // If not is. + dereference ? 5 : 6, // If not mode. + dereference ? 4 : 5, // If not owner. + }; + for (; i < 21; ++i) { // Skip the "if not XXX" types as they are determined later on. if (i > 12 && i < 19) continue; - if (fl_string_dynamic_compare(if_type_strings[i], arguments.array[0]) == F_equal_to) { + if (fl_string_dynamic_compare(if_type_strings[i], arguments.array[k]) == F_equal_to) { state_process->condition = if_type_codes[i]; break; @@ -746,7 +763,7 @@ extern "C" { fl_print_format("%r%[%QUnsupported '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context); fl_print_format("%[%r%]", data_make->error.to.stream, data_make->error.notable, if_and_or, data_make->error.notable); fl_print_format("%[' type '%]", data_make->error.to.stream, data_make->error.context, data_make->error.context); - fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[0], data_make->error.notable); + fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[k], data_make->error.notable); fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); funlockfile(data_make->error.to.stream); @@ -757,9 +774,11 @@ extern "C" { return; } + ++k; + // Identify and convert to the appropriate if not condition. if (state_process->condition == fake_make_operation_if_type_if_not_e) { - if (arguments.used < 2) { + if (arguments.used < 1 + k) { fake_print_error_requires_more_arguments(data_make); *status = F_status_set_error(F_failure); @@ -769,7 +788,7 @@ extern "C" { for (; j < 6; ++j) { - if (fl_string_dynamic_compare(if_not_type_strings[j], arguments.array[1]) == F_equal_to) { + if (fl_string_dynamic_compare(if_not_type_strings[j], arguments.array[k]) == F_equal_to) { state_process->condition = if_not_type_codes[j]; break; @@ -783,7 +802,7 @@ extern "C" { fl_print_format("%r%[%QUnsupported '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context); fl_print_format("%[%r%]", data_make->error.to.stream, data_make->error.notable, if_and_or, data_make->error.notable); fl_print_format("%[' not type '%]", data_make->error.to.stream, data_make->error.context, data_make->error.context); - fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[1], data_make->error.notable); + fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[k], data_make->error.notable); fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); funlockfile(data_make->error.to.stream); @@ -812,13 +831,13 @@ extern "C" { } if (state_process->condition == fake_make_operation_if_type_if_defined_e || state_process->condition == fake_make_operation_if_type_if_not_defined_e) { - if (fl_string_dynamic_compare(fake_make_operation_argument_environment_s, j == 6 ? arguments.array[1] : arguments.array[2]) == F_equal_to_not) { - if (fl_string_dynamic_compare(fake_make_operation_argument_parameter_s, j == 6 ? arguments.array[1] : arguments.array[2]) == F_equal_to_not) { + if (fl_string_dynamic_compare(fake_make_operation_argument_environment_s, arguments.array[k]) == F_equal_to_not) { + if (fl_string_dynamic_compare(fake_make_operation_argument_parameter_s, arguments.array[k]) == F_equal_to_not) { if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { flockfile(data_make->error.to.stream); fl_print_format("%r%[%QUnsupported define type '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context); - fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, j == 6 ? arguments.array[1] : arguments.array[2], data_make->error.notable); + fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[k], data_make->error.notable); fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); funlockfile(data_make->error.to.stream); @@ -831,7 +850,7 @@ extern "C" { return; } else if (state_process->condition == fake_make_operation_if_type_if_equal_e || state_process->condition == fake_make_operation_if_type_if_equal_not_e) { - if (arguments.used < 3) { + if (arguments.used < 2 + k) { fake_print_error_requires_more_arguments(data_make); *status = F_status_set_error(F_failure); @@ -845,13 +864,13 @@ extern "C" { else if (state_process->condition == fake_make_operation_if_type_if_group_e || state_process->condition == fake_make_operation_if_type_if_is_e || state_process->condition == fake_make_operation_if_type_if_mode_e || state_process->condition > fake_make_operation_if_type_if_not_exists_e && state_process->condition < fake_make_operation_if_type_if_success_e) { if (state_process->condition == fake_make_operation_if_type_if_mode_e || state_process->condition == fake_make_operation_if_type_if_not_mode_e) { - if (fl_string_dynamic_compare(fake_make_operation_argument_is_s, arguments.array[1]) == F_equal_to_not) { - if (fl_string_dynamic_compare(fake_make_operation_argument_has_s, arguments.array[1]) == F_equal_to_not) { + if (fl_string_dynamic_compare(fake_make_operation_argument_is_s, arguments.array[k]) == F_equal_to_not) { + if (fl_string_dynamic_compare(fake_make_operation_argument_has_s, arguments.array[k]) == F_equal_to_not) { if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { flockfile(data_make->error.to.stream); fl_print_format("%r%[%QUnsupported %smode type '%]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, j == 6 ? "" : "not ", data_make->error.context); - fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[1], data_make->error.notable); + fl_print_format("%[%Q%]", data_make->error.to.stream, data_make->error.notable, arguments.array[k], data_make->error.notable); fl_print_format("%['.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s); funlockfile(data_make->error.to.stream); @@ -866,18 +885,18 @@ extern "C" { f_file_mode_t mode_rule = 0; uint8_t replace = 0; - *status = fake_make_get_id_mode(data_make->data, data_make->error, j == 6 ? arguments.array[2] : arguments.array[3], &mode_rule, &replace); + *status = fake_make_get_id_mode(data_make->data, data_make->error, arguments.array[++k], &mode_rule, &replace); if (F_status_is_error(*status)) return; - i = j == 6 ? 3 : 4; + i = ++k; } else if (state_process->condition == fake_make_operation_if_type_if_group_e || state_process->condition == fake_make_operation_if_type_if_not_group_e) { gid_t id = 0; - *status = fake_make_get_id_group(data_make->data, data_make->error, j == 6 ? arguments.array[1] : arguments.array[2], &id); + *status = fake_make_get_id_group(data_make->data, data_make->error, arguments.array[k++], &id); if (F_status_is_error(*status)) return; - i = j == 6 ? 2 : 3; + i = k; } else if (state_process->condition == fake_make_operation_if_type_if_is_e || state_process->condition == fake_make_operation_if_type_if_not_is_e) { @@ -887,7 +906,7 @@ extern "C" { // fifo = 0x8 (0000 1000) invalid = 0x80 (1000 0000) uint8_t type_file = 0; - for (i = j == 6 ? 1 : 2; i < arguments.used; ++i) { + for (i = k; i < arguments.used; ++i) { if (fl_string_dynamic_compare(fake_make_operation_argument_if_is_for_s, arguments.array[i]) == F_equal_to) { ++i; @@ -940,10 +959,10 @@ extern "C" { else if (state_process->condition == fake_make_operation_if_type_if_owner_e || state_process->condition == fake_make_operation_if_type_if_not_owner_e) { uid_t id = 0; - *status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[1], &id); + *status = fake_make_get_id_owner(data_make->data, data_make->error, arguments.array[k++], &id); if (F_status_is_error(*status)) return; - i = j == 6 ? 2 : 3; + i = k; } if (i < arguments.used) { @@ -966,7 +985,7 @@ extern "C" { else if (state_process->condition != fake_make_operation_if_type_if_exists_e && state_process->condition != fake_make_operation_if_type_if_is_e) { // The existence tests do not need to happen here for *_if_exists and *_if_is as those two types will handle performing them during the process stage. - status_file = f_file_exists(arguments.array[i]); + status_file = f_file_exists(arguments.array[i], dereference); if (status_file == F_false) { status_file = F_status_set_error(F_file_found_not); @@ -984,7 +1003,7 @@ extern "C" { } } else if (state_process->condition == fake_make_operation_if_type_if_greater_e || state_process->condition == fake_make_operation_if_type_if_greater_equal_e || state_process->condition == fake_make_operation_if_type_if_less_e || state_process->condition == fake_make_operation_if_type_if_less_equal_e) { - if (arguments.used < 3) { + if (arguments.used < 2 + k) { fake_print_error_requires_more_arguments(data_make); *status = F_status_set_error(F_failure); @@ -998,7 +1017,7 @@ extern "C" { bool is_negative = F_false; // @fixme there needs to handle converting numbers with decimals (like 1.01), perhaps operate on them as strings or provide a special processor. - for (i = 1; i < arguments.used; ++i, status_number = F_none) { + for (i = k; i < arguments.used; ++i, status_number = F_none) { if (arguments.array[i].used) { range.start = 0; @@ -1110,7 +1129,7 @@ extern "C" { for (f_array_length_t i = 0; i < arguments.used - 1; ++i) { - if (f_file_exists(arguments.array[i]) != F_true) { + if (f_file_exists(arguments.array[i], F_true) != F_true) { if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) { flockfile(data_make->error.to.stream); @@ -1221,6 +1240,7 @@ extern "C" { } *status = F_status_set_error(F_failure); + break; } } // for diff --git a/level_3/fake/documents/fakefile.txt b/level_3/fake/documents/fakefile.txt index b14db85..064b91a 100644 --- a/level_3/fake/documents/fakefile.txt +++ b/level_3/fake/documents/fakefile.txt @@ -510,3 +510,13 @@ Fakefile Documentation: - work:value\: This variable holds the value part of the "work" program parameters, such as "work/". + + The Content "no_dereference" may be specified in certain cases relating to files. + These cases operate on a file that can be a link itself or the link target. + The default behavior is normally to dereference the link target. + + For example, consider a symbolic link, called "some_file", that points to a file that does not exist (which means that the link in question is a broken link). + The Operation "if exists some_file" would return false. + The Operation "if no_dereference exists some_file" would return true. + This is because the symbolic link itself, "some_file", does exist but the file it is pointing to does not. + The "no_dereference" is ignored for conditions that do not need it. diff --git a/level_3/fake/specifications/fakefile.txt b/level_3/fake/specifications/fakefile.txt index 5474e02..a9d24fb 100644 --- a/level_3/fake/specifications/fakefile.txt +++ b/level_3/fake/specifications/fakefile.txt @@ -42,7 +42,7 @@ Fakefile Specification: The build settings may also be specified in the Settings Section. The Section Operation Objects are\: - - and: One or more Content. First Content is the condition, remaining Content are specific to the condition. + - and: One or more Content. First Content is the condition or "no_dereference" (when "no_dereference", then the Second Content is the condition, etc..), remaining Content are specific to the condition. - break: Zero or One Content. If specified, First content must be one of "success" or "failure". - build: Zero or One Content. First Content represents file name of the settings file to use. - clean: Zero Content. @@ -55,18 +55,18 @@ Fakefile Specification: - else: Zero Content. - exit: Zero or One Content. If specified, First content must be one of "succeed" or "fail". - fail: One Content. First Content must be one of "exit", "warn", or "ignore" (case-sensitive). - - group: Two or more Content. First Content is group name or number, remaining Content are paths to files. - - groups: Two or more Content. First Content is group name or number, remaining Content are paths to files. - - if: One or more Content. First Content is the condition, remaining Content are specific to the condition. + - group: Two or more Content. First Content is group name, number, or "no_dereference" (when "no_dereference", then the second Content is the group name or number, etc..), remaining Content are paths to files. + - groups: Two or more Content. First Content is group name, number, or "no_dereference" (when "no_dereference", then the second Content is the group name or number, etc..), remaining Content are paths to files. + - if: One or more Content. First Content is the condition or is "no_dereference" (when "no_dereference", then the Second Content is the condition, etc..), remaining Content are specific to the condition. - index: One or more Content. - link: Two Content. First Content is the link target file and second Content is the pointer file (the link). - mode: Two or more Content. First Content is the mode, remaining Content are paths to files. - modes: Two or more Content. First Content is the mode, remaining Content are paths to files. - move: Two or more Content representing paths to files. - operate: One Content. First Content is the name of a valid Section Object, except for the reserved Section Objects. - - or: One or more Content. First Content is the condition, remaining Content are specific to the condition. - - owner: Two or more Content. First Content is group name or number, remaining Content are paths to files. - - owners: Two or more Content. First Content is group name or number, remaining Content are paths to files. + - or: One or more Content. First Content is the condition or "no_dereference" (when "no_dereference", then the Second Content is the condition, etc..), remaining Content are specific to the condition. + - owner: Two or more Content. First Content is owner name, number, or "no_dereference" (when "no_dereference", then the second Content is the owner name or number, etc..), remaining Content are paths to files. + - owners: Two or more Content. First Content is owner name, number, or "no_dereference" (when "no_dereference", then the second Content is the owner name or number, etc..), remaining Content are paths to files. - parameter: First Content represents variable name (case-sensitive), remaining Content represents the value. - pop: Zero Content. - print: Zero or more Content. @@ -85,11 +85,13 @@ Fakefile Specification: - <=: Two or more Content. - <>: Two or more Content. - defined: First Content is either "parameter" or "environment". Second or more Content are valid names, such that for "parameter" it is a valid IKI name and for "environment" it is a valid environment variable name. + - exists: One or more Content representing the files to check the existence of. - failure: has no other Content. - group: First Content is the name of a group. Second or more Content are paths to files. - - is: First Content is a list of "block", "character", "directory", "fifo", "link", "regular" , or "socket" followed by "for" and then the Remaining Content that are paths to files. - - mode: First Content is either "is" or "has". Second Content is a valid file mode. Third or more Content are paths to files. - - not: First Content is one of "defined", "exists", "group", "is", "mode", or "owner" and all remaining Content are based on the First Content's "if" Section Operation Content rules. + - is: First Content is a list of "block", "character", "no_dereference", "directory", "fifo", "link", "regular" , or "socket" followed by "for" and then the Remaining Content that are paths to files. + - mode: First Content is either "has", "is", or "no_dereference". Second Content is a valid file mode. Third or more Content are paths to files. + - no_dereference: A non-condition inserted before any of "exists", "is", and "mode" (then the second Content is the actual condition followed by any Content associated with that condition). + - not: First Content is one of "defined", "exists", "group", "is", "mode", "no_dereference", or "owner" and all remaining Content are based on the First Content's "if" Section Operation Content rules. - owner: First Content is the name of an owner. Second or more Content are paths to files. - success: has no other Content. diff --git a/level_3/utf8/c/utf8.c b/level_3/utf8/c/utf8.c index 1730488..3d78dc6 100644 --- a/level_3/utf8/c/utf8.c +++ b/level_3/utf8/c/utf8.c @@ -289,7 +289,7 @@ extern "C" { index = main->parameters.array[utf8_parameter_from_file_e].values.array[i]; if (data.argv[index].used) { - if (!f_file_exists(data.argv[index])) { + if (f_file_exists(data.argv[index], F_true) != F_true) { utf8_print_error_parameter_file_not_found(&data, F_true, data.argv[index]); if (F_status_is_error_not(status)) {