Skip to content

Commit

Permalink
Restore v21 behavior of --directories
Browse files Browse the repository at this point in the history
Prior to 68b4ce5, the -d flag ensured that search results included
directories. After that commit, the -d flag acted as a toggle,
*restricting* the results to directories. This change restores the
former behavior and improves the manpage to make this explicit.

Fixes #67.
  • Loading branch information
falconindy committed Sep 29, 2024
1 parent 6c15c25 commit 8362856
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion man/pkgfile.pod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Return only files which are contained within a bin or sbin directory.

=item B<-d>, B<--directories>

Match directories in search results.
Additionally include directories in search results.

=item B<-g>, B<--glob>

Expand Down
9 changes: 3 additions & 6 deletions src/pkgfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,11 @@ std::unique_ptr<filter::Filter> Pkgfile::BuildFilterFromOptions(
std::move(filter));
}

std::unique_ptr<filter::Filter> dir_filter =
std::make_unique<filter::Directory>();
if (!options.directories) {
dir_filter = std::make_unique<filter::Not>(std::move(dir_filter));
filter = std::make_unique<filter::And>(
std::make_unique<filter::Not>(std::make_unique<filter::Directory>()),
std::move(filter));
}

filter =
std::make_unique<filter::And>(std::move(dir_filter), std::move(filter));
}

return filter;
Expand Down
9 changes: 9 additions & 0 deletions tests/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def testSearchDirectories(self):
testing/dhcpcd
''').lstrip('\n'))

r = self.Pkgfile(['-s', '-d', '/usr/bin/dhcpcd'])
self.assertEqual(r.returncode, 0)

self.assertEqual(
r.stdout.decode(),
textwrap.dedent('''
testing/dhcpcd
''').lstrip('\n'))

def testSearchCaseInsensitive(self):
r = self.Pkgfile(['-s', '-i', 'mKiNiTcPiO'])
self.assertEqual(r.returncode, 0)
Expand Down

0 comments on commit 8362856

Please sign in to comment.