When lfs find is used with multiple paths and the first non-path
option is a '!' or an option without an argument like '-print',
the code skipped the final path because it assumed that the first
non-path option would be an option with an argument.
This commit resolves the bug by remembering the last-processed argv
index so that the index of the final path argument is correct whether
the next option consumes 2 indexes or just 1.
Signed-off-by: Thomas Bertschinger <bertschinger@lanl.gov>
Change-Id: I03133a43641af7a53a20d947b8ef82529e453251
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51578
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
}
run_test 56edb "check lfs find --links for directory striped on multiple MDTs"
+test_56ef() {
+ local dir=$DIR/$tdir
+ local dir1=$dir/d1
+ local dir2=$dir/d2
+ local nfiles
+
+ test_mkdir -p $dir
+
+ mkdir $dir1
+ mkdir $dir2
+
+ touch $dir1/f
+ touch $dir2/f
+
+ nfiles=$($LFS find $dir1 $dir2 ! -type d | wc -l)
+ (( $nfiles == 2 )) ||
+ error "(1) lfs find expected 2 files, got $nfiles"
+
+ nfiles=$($LFS find $dir1 $dir2 -type f | wc -l)
+ (( $nfiles == 2 )) ||
+ error "(2) lfs find expected 2 files, got $nfiles"
+
+ nfiles=$($LFS find -type f $dir1 $dir2 | wc -l)
+ (( $nfiles == 2 )) ||
+ error "(3) lfs find expected 2 files, got $nfiles"
+}
+run_test 56ef "lfs find with multiple paths"
+
test_57a() {
[ $PARALLEL == "yes" ] && skip "skip parallel run"
# note test will not do anything if MDS is not local
.has_arg = required_argument },
{ .val = 'z', .name = "ext-size", .has_arg = required_argument },
{ .name = NULL } };
+ int prev_optind = optind;
int optidx = 0;
int pathstart = -1;
int pathend = -1;
goto err;
}
if (!isoption && pathstart == -1)
- pathstart = optind - 1;
+ pathstart = prev_optind;
if (isoption && pathstart != -1 && pathend == -1)
- pathend = optind - 2;
+ pathend = prev_optind;
+
+ prev_optind = optind;
+
switch (c) {
case 0:
/* Long options. */