Whamcloud - gitweb
LU-15504 utils: lfs find -ls function 43/55443/11
authorMaximilian Dilger <mdilger@whamcloud.com>
Sun, 16 Jun 2024 01:55:46 +0000 (21:55 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 8 Aug 2024 00:15:57 +0000 (00:15 +0000)
Added -ls function for lfs find. It is equivalent to using
printf "%i/t%k/t%M/t%n/t%u/t%g/t%s/t%t/t%p/n"

Signed-off-by: Maximilian Dilger <mdilger@whamcloud.com>
Change-Id: If84687915a2f71be81ee8adc5c9402371d635956
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55443
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Anjus George <georgea@ornl.gov>
lustre/tests/sanity.sh
lustre/utils/lfs.c

index 7d57de4..8a2662b 100755 (executable)
@@ -9189,6 +9189,19 @@ test_56eaa() {
 }
 run_test 56eaa "test lfs find -printf added functions"
 
+test_56eab() {
+       touch $DIR/$tfile
+       local lfs_ls=($($LFS find $DIR -name $tfile -ls))
+       local find_ls=($(find $DIR -name $tfile -ls))
+
+# "-1" is last field, since dates are not printed exactly the same.
+       for ((i = -1; i < 7; i++)); do
+               [[ "${lfs_ls[i]}" == "${find_ls[i]}" ]] ||
+                       error "expected '${lfs_ls[i]}' but got '${find_ls[i]}'"
+       done
+}
+run_test 56eab "test lfs find -ls function"
+
 test_56eb() {
        local dir=$DIR/$tdir
        local subdir_1=$dir/subdir_1
index b1c6299..a172a94 100755 (executable)
@@ -3533,6 +3533,7 @@ enum {
        LFS_INHERIT_RR_OPT,
        LFS_FIND_PERM,
        LFS_PRINTF_OPT,
+       LFS_PRINTF_LS,
        LFS_NO_FOLLOW_OPT,
        LFS_HEX_IDX_OPT,
        LFS_STATS_OPT,
@@ -5449,6 +5450,8 @@ static int lfs_find(int argc, char **argv)
        { .val = 'L',   .name = "layout",       .has_arg = required_argument },
        { .val = LFS_LINKS_OPT,
                        .name = "links",        .has_arg = required_argument },
+       { .val = LFS_PRINTF_LS,
+                       .name = "ls",           .has_arg = no_argument },
        { .val = 'm',   .name = "mdt",          .has_arg = required_argument },
        { .val = 'm',   .name = "mdt-index",    .has_arg = required_argument },
        { .val = 'm',   .name = "mdt_index",    .has_arg = required_argument },
@@ -6144,6 +6147,10 @@ err_free:
                case LFS_PRINTF_OPT:
                        param.fp_format_printf_str = strdup(optarg);
                        break;
+               case LFS_PRINTF_LS:
+                       param.fp_format_printf_str =
+                               strdup("%i\t%k\t%M\t%n\t%u\t%g\t%s\t%t\t%p\n");
+                       break;
                case LFS_PROJID_OPT:
                        rc = name2projid(&param.fp_projid, optarg);
                        if (rc) {