Commit Graph

19 Commits

Author SHA1 Message Date
Tim Schumacher
0ca63cfd6e find: Implement support for multiple directories 2021-12-03 15:39:00 +01:00
Tim Schumacher
5a21c3b389 find: Use a Vector for parsing instead of moving optind 2021-12-03 15:39:00 +01:00
Tim Schumacher
4ca35ac1b8 find: Port to LibMain 2021-12-03 15:39:00 +01:00
Sergey Bugaev
6c9343e262 Userland: Also cache d_type in find(1)
Since readdir() actually gives us the file type, we don't have
to stat it again to know whether it's a directory! This means that
'find /' can process the majority of files without ever calling
stat() on them, simply by reading directories.

In addition, the TypeCommand (-t) can make use of this info too,
so, for instance, a 'find / -t d' does not need to stat anything
either.

This gives us a final huge speedup :^)
2021-08-18 18:13:59 +02:00
Sergey Bugaev
548a880310 Userland: Cache stat in find(1)
We have multiple commands that are implemented in terms of stat.
Let's cache the stat in FileData after we query it once.

This gives us another large speed-up :^)
2021-08-18 18:13:59 +02:00
Sergey Bugaev
d4232d5ee2 Userland: Simplify recursion in find(1)
Now walk_tree() itself checks whether it should descend into a file
(if the file is a directory) or not.
2021-08-18 18:13:59 +02:00
Sergey Bugaev
ad15d0c880 Userland: Ditch Core::DirIterator for readdir() in find(1)
While Core::DirIterator is nice C++ API, we want more low-level
control here. In particular, we want to open the directory using
openat(), to also not pay the cost of re-traversing the path
components we have already resolved previously.

This gives us another nice speedup :^)

Also, in the future commits this will allow us to make use of more
data from the returned struct dirent, to speed things up even further.
2021-08-18 18:13:59 +02:00
Sergey Bugaev
4c126ea908 Userland: Use fstatat() in find(1)
This speeds things up noticeably :^)

The idea here is that a directory fd is a way to hold onto
the results of path resolution that the kernel has already done
for us. This way we don't ask the kernel to resolve the same
parent directories over and over.
2021-08-18 18:13:59 +02:00
Sergey Bugaev
e526a7641f Userland: Wrap path a into struct in find(1)
Also, replace the raw string by a LexicalPath.

Both are weird changes to make on their own; but they set
the stage for what's to come next.
2021-08-18 18:13:59 +02:00
Brian Gianforcaro
219d4ba376 Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
Linus Groh
f5c35fccca Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
Gunnar Beutner
f5c4d86592 Utilites: Make find respect lack of -L when iterating over directories
Previously find would follow symlinks when iterating over directories
even though the -L argument was not specified.
2021-05-18 08:11:42 +02:00
Jean-Baptiste Boric
3038edab00 Utilities: Correct non-standard assert macros includes 2021-05-17 18:14:05 +01:00
Jean-Baptiste Boric
e16894af5a LibC: Do not include errno.h inside unistd.h
POSIX does not mandate this, therefore let's not do it.
2021-05-14 22:24:02 +02:00
Valtteri Koskivuori
9e49895bbf Userland: Fix some weird syntax in find
Spotted this while trying to fix a bug. clang-format approved.
2021-05-07 22:29:19 +02:00
Valtteri Koskivuori
33af7075e7 Userland: Remove extra slashes from find output
I noticed while testing `find` that the output of `find` contains extra
forward slashes if the root path has a trailing slash. This patch fixes
that issue by passing the root path through LexicalPath before
proceeding.
2021-05-07 22:25:39 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
ececac65c2 Userland: Move command-line utilities to Userland/Utilities/ 2021-01-12 12:04:09 +01:00