summaryrefslogtreecommitdiffstats
path: root/bftw.c
AgeCommit message (Collapse)Author
2018-06-23bftw: Introduce bftw_reader typeTavian Barnes
2018-04-07bftw: Replace the circular buffer queue with a linked listTavian Barnes
The performance is within 1% with much simpler code.
2018-02-01bftw: Open-code the "."/".." checksTavian Barnes
GCC doesn't (yet) produce very fast code for strcmp() against constant strings (see https://gcc.gnu.org/PR78809), so hand-coding the comparison manually helps significantly.
2018-02-01bftw: Fix the heap implementationTavian Barnes
There were two problems: - bubble_down() would always bubble the entry all the way down the heap, instead of stopping at the appropriate place - remove() may need to bubble the replacement entry *up* the heap, if it came from a different subtree
2018-01-08stat: New wrapper around the stat() familyTavian Barnes
This lets bfs transparently support the new statx() system call on Linux, giving it access to file birth times.
2018-01-06bftw: Rename 'last' to 'previous'Tavian Barnes
2017-08-22Avoid multiple extra stat()s of broken symlinks for -xtypeTavian Barnes
2017-08-12Unify broken symlink handlingTavian Barnes
Rather than open-code the fallback logic for broken symlinks everywhere it's needed, introduce a new xfstatat() utility function that performs the fallback automatically. Using xfstatat() consistently fixes a few bugs, including cases where broken symlinks are given as arguments to predicates like -samefile.
2017-08-10bftw: Assert that the queue is empty when freeing itTavian Barnes
2017-07-29util: Define O_DIRECTORY to 0 if it's not already definedTavian Barnes
2017-07-27Re-license under the BSD Zero Clause LicenseTavian Barnes
2017-07-09Handle ENOTDIR the same as ENOENTTavian Barnes
For a/b/c, ENOTDIR is returned instead of ENOENT if a or b are not directories. Handle this uniformly when detecting broken symlinks, readdir races, etc.
2017-07-09bftw: Rename and refactor the internalsTavian Barnes
2017-07-08bftw: Fix ENAMETOOLONG handling when the root is closedTavian Barnes
The root has depth == 0, but we still need to include it in the components array.
2017-07-08bftw: Recover from ENAMETOOLONGTavian Barnes
It is always possible to force a breadth-first traversal to encounter ENAMETOOLONG, regardless of the dircache eviction policy. As a concrete example, consider this directory structure: ./1/{NAME_MAX}/{NAME_MAX}/{NAME_MAX}/... (longer than {PATH_MAX}) ./2/{NAME_MAX}/{NAME_MAX}/{NAME_MAX}/... ./3/{NAME_MAX}/{NAME_MAX}/{NAME_MAX}/... ... (more than RLIMIT_NOFILE directories under .) Eventually, the next file to be processed will not have any parents in the cache, as the cache can only hold RLIMIT_NOFILE entries. Then the whole path must be traversed from ., which will exceed {PATH_MAX} bytes. Work around this by performing a component-by-component traversal manually when we see ENAMETOOLONG. This is required by POSIX: > The find utility shall be able to descend to arbitrary depths in a file > hierarchy and shall not fail due to path length limitations (unless a > path operand specified by the application exceeds {PATH_MAX} > requirements).
2017-07-08Revert "bftw: Don't store the terminating '\0' in dircache_entry names."Tavian Barnes
This reverts commit 20860becb5a0e89ee2aaaddbb0ba1eb248552640. The terminating NUL will be useful for the upcoming per-component traversal to handle ENAMETOOLONG.
2017-05-17bftw: Remove unused parameter to dircache_entry_base()Tavian Barnes
2017-04-24Release 1.01.0Tavian Barnes
2017-04-08Move bftw_typeflag converters to util.cTavian Barnes
2017-03-22bftw: Only rebuild the part of the path that changesTavian Barnes
Quadratic complexity is still possible for directory structures like root -- a -- a -- a -- a ... | +- b -- b -- b -- b ... But for most realistic directory structures, bfs should now spend less time building paths. (Of course if you print every path, overall complexity is quadratic anyway.)
2017-03-20bftw: Fix quadratic reference counting complexityTavian Barnes
dircache_entry refcounts used to count every single descendant, resulting in n refcount updates to create/delete an entry at depth n, and thus O(n^2) complexity overall for deep directory structures. Fix it by only counting direct children instead. The cache eviction policy is changed to prefer shallower entries in all cases, attempting to save at least some of the benefit of the previous accounting scheme. Unfortunately, the average number of traversed components for openat() calls still went up by ~20%, but the performance in practice is roughly unchanged in my tests.
2017-03-16Color link targets for -lsTavian Barnes
Fixes #18.
2017-02-09bftw: Make the nameoff of "///" point to "/"Tavian Barnes
This simplifies a few things such as -name handling for ///.
2017-02-09bftw: Add the DIR* to bftw_stateTavian Barnes
Can't forget to close it that way.
2017-02-08Add support for -x?type with multiple typesTavian Barnes
This functionality is already part of GNU findutils git.
2017-02-07bftw: Add mising closedir() to error pathTavian Barnes
2017-02-06bftw: Plug a leak if dirqueue_push() failsTavian Barnes
If bftw_add() succeeds but dirqueue_push() fails, we need to clean up the just-added dircache_entry. Otherwise it will leak, and we'll also fail the cache->size == 0 assertion. Fix it by extracting the dircache-related parts of bftw_pop() into a new helper function bftw_gc(), and call it from bftw_pop() as well as the bftw_push() failure path.
2017-02-05bftw: Compute nameoff correctly for the root in BFTW_DEPTH modeTavian Barnes
2017-02-05Implement -printf/-fprintfTavian Barnes
Based on a patch by Fangrui Song <i@maskray.me>. Closes #16.
2016-12-18Implement -regex, -iregex, and -regextype/-ETavian Barnes
2016-12-17bftw: Clean up the dirqueue implementation a bitTavian Barnes
2016-12-04Move portability code into util.hTavian Barnes
2016-11-23bftw: Infer the flags in ftwbuf_stat()Tavian Barnes
2016-11-21bftw: Make a defensive copy of the ftwbufTavian Barnes
The callback may modify the ftwbuf, but we check it after the callback (for typeflag and statbuf). Have them mutate a copy instead.
2016-11-21bftw: Always initialize dircache_entry::{dev,ino}Tavian Barnes
If stat() fails, they won't get filled in otherwise. Then cycle detection would have read uninitialized values.
2016-11-21bftw: Make bftw_flags more similar to fts() options.Tavian Barnes
2016-11-14Check for readdir() errors everywhere.Tavian Barnes
2016-11-13bftw: Keep trailing slashes on the root in BFTW_DEPTH mode.Tavian Barnes
2016-11-03bftw: Don't fail just because we couldn't open/read a directory.Tavian Barnes
With BFTW_RECOVER set, we're not supposed to fail just because a single measly directory couldn't be handled. But using state.error as scratch space made us fail in this case. The end result is that #7 resurfaced, so fix it again.
2016-10-24Implement -ignore_readdir_race.Tavian Barnes
2016-10-02bftw: Add support for some exotic file types, where available.Tavian Barnes
2016-10-02bftw: Handle errors from readdir().Tavian Barnes
2016-09-10bftw: Fix do/to typo in a comment.Tavian Barnes
2016-08-24bftw: Initialize typeflag to BFTW_UNKNOWN.Tavian Barnes
It was totally broken on filesystems that spit out DT_UNKNOWN.
2016-05-22dstring: Clean up the API a bit.Tavian Barnes
2016-05-17bftw: Use realloc() to grow the dirqueue.Tavian Barnes
2016-05-17bftw: Remove some debugging counters that were left in accidentally.Tavian Barnes
2016-04-13dstring: Split out the dynamic string logic.Tavian Barnes
2016-02-23bftw: Update at_flags when not following a broken symbolic link.Tavian Barnes
2016-02-23bftw: Plug a leak when the root is not a directory.Tavian Barnes