diff --git a/src/builtins/path.cpp b/src/builtins/path.cpp index be062e23f..5cf368652 100644 --- a/src/builtins/path.cpp +++ b/src/builtins/path.cpp @@ -807,9 +807,8 @@ static int path_filter(parser_t &parser, io_streams_t &streams, int argc, const int n_transformed = 0; arg_iterator_t aiter(argv, optind, streams, opts.null_in); while (const wcstring *arg = aiter.nextstr()) { - if ((!opts.invert || (!opts.have_perm && !opts.have_type)) && filter_path(opts, *arg)) { + if ((!opts.have_perm && !opts.have_type) || (filter_path(opts, *arg) != opts.invert)) { // If we don't have filters, check if it exists. - // (for match this is done by the glob already) if (!opts.have_type && !opts.have_perm) { bool ok = !waccess(*arg, F_OK); if (ok == opts.invert) continue; diff --git a/tests/checks/path.fish b/tests/checks/path.fish index d9ef9897a..3f2aa2f48 100644 --- a/tests/checks/path.fish +++ b/tests/checks/path.fish @@ -94,6 +94,17 @@ chmod +x bin/* path filter bin argagagji # The (hopefully) nonexistent argagagji is filtered implicitly: # CHECK: bin + +# With --invert, the existing bin is filtered +path filter --invert bin argagagji +# CHECK: argagagji + +# With --invert and a type, bin fails the type, +# and argagagji doesn't exist, so both are printed. +path filter -vf bin argagagji +# CHECK: bin +# CHECK: argagagji + path filter --type file bin bin/fish # Only fish is a file # CHECK: bin/fish