Skip to content

Commit bd7ed10

Browse files
committed
df: fix O(n²) performance in deeply nested directories by checking is_absolute() before is_symlink()
1 parent da664ec commit bd7ed10

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/uu/df/src/df.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
311311
// but `vmi` is probably not very long in practice.
312312
if is_included(&mi, opt) && is_best(&mounts, &mi) {
313313
let dev_path: &Path = Path::new(&mi.dev_name);
314-
if dev_path.is_symlink() {
314+
// Only check is_symlink() for absolute paths. For non-absolute paths
315+
// like "tmpfs", "sysfs", etc., is_symlink() would resolve relative to
316+
// the current working directory, which is extremely slow in deeply
317+
// nested directories (O(n) syscalls where n is the directory depth).
318+
if dev_path.is_absolute() && dev_path.is_symlink() {
315319
if let Ok(canonicalized_symlink) = uucore::fs::canonicalize(
316320
dev_path,
317321
uucore::fs::MissingHandling::Existing,

0 commit comments

Comments
 (0)