From: Kevin Day Date: Fri, 14 Aug 2020 02:23:34 +0000 (-0500) Subject: Progress: implement modes operation with todo for recursion and fix documentation X-Git-Tag: 0.5.0~48 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=4174a8ac647623c2ebbb888f18122d43199d8dfd;p=fll Progress: implement modes operation with todo for recursion and fix documentation Recursion will be written at a later date. Just copy over the mode operation code just like it is done with owners (vs owner) and groups (vs group). Fix a copy & paste mistake where I forgot to change the wording in the mode documentation. --- diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 1d1f515..24111bf 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -1556,7 +1556,40 @@ extern "C" { } if (operation == fake_make_operation_type_modes) { - // @todo + f_file_mode mode_rule = 0; + uint8_t replace = 0; + + *status = fake_make_get_id_mode(data, arguments.array[0], &mode_rule, &replace); + if (F_status_is_error(*status)) return; + + mode_t mode = 0; + + struct stat stat_file; + + for (f_array_length i = 1; i < arguments.used; i++) { + // @todo recursive. + mode = 0; + memset(&stat_file, 0, sizeof(struct stat)); + + *status = f_file_stat(arguments.array[i].string, F_true, &stat_file); + if (F_status_is_error(*status)) { + fake_print_error_file(data, *status, "f_file_stat", arguments.array[i].string, "change mode of", F_true, F_true); + break; + } + + *status = f_file_mode_determine(stat_file.st_mode, mode_rule, replace, f_macro_file_type_is_directory(stat_file.st_mode), &mode); + if (F_status_is_error(*status)) { + fake_print_error_file(data, *status, "f_file_mode_determine", arguments.array[i].string, "change mode of", F_true, F_true); + break; + } + + *status = f_file_mode_set(arguments.array[i].string, mode); + if (F_status_is_error(*status)) { + fake_print_error_file(data, *status, "f_file_mode_set", arguments.array[i].string, "change mode of", F_true, F_true); + break; + } + } // for + return; } diff --git a/level_3/fake/specifications/fakefile.txt b/level_3/fake/specifications/fakefile.txt index d1c95e0..ad01f9a 100644 --- a/level_3/fake/specifications/fakefile.txt +++ b/level_3/fake/specifications/fakefile.txt @@ -54,8 +54,8 @@ Fakefile Specification: - 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. - 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 group name or number, remaining Content are paths to files. - - modes: Two or more Content. First Content is group name or number, remaining Content are paths to files. + - 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. - operate: One Content. First Content is the name of a valid Section Object, except for the reserved Section Objects. - 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.