Skip to content

arg: avoid revisiting directories through symlink cycles - #419

Open
hja-oss wants to merge 2 commits into
lsof-org:masterfrom
hja-oss:fix/directory-symlink-cycles
Open

hja-oss wants to merge 2 commits into
lsof-org:masterfrom
hja-oss:fix/directory-symlink-cycles

Conversation

@hja-oss

@hja-oss hja-oss commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Recursive searches with -x l +D can repeatedly traverse symlink cycles, causing enormous redundant work even in tiny directories.

Skip symlinked directories already recorded during the current search, while preserving links to new directories and independent directory searches.

Comment thread src/arg.c Outdated
}
/* Do not revisit directories recorded by this search. */
if (descend && (sb.st_mode & S_IFMT) == S_IFDIR) {
for (sfp = Sfile; sfp != sfile_start; sfp = sfp->next) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned about the performance of this check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve replaced the linear scan with a dynamically growing, per-search hash set keyed by device and inode. It only tracks directories and is enabled for recursive symlink following.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants