Skip to content

Do not raise ENOENT for a dangling symlink argument - #26

Open
carlosdanielpohlod wants to merge 1 commit into
ruby:masterfrom
carlosdanielpohlod:fix-broken-symlink-arg
Open

carlosdanielpohlod wants to merge 1 commit into
ruby:masterfrom
carlosdanielpohlod:fix-broken-symlink-arg

Conversation

@carlosdanielpohlod

Copy link
Copy Markdown

Fixes #18.

Find.find rejects a dangling symlink passed as an argument:

File.symlink("nowhere", "broken")
Find.find("broken") { |path| puts path }
# find.rb:55:in 'block in find': No such file or directory - broken (Errno::ENOENT)

The same link is yielded normally when it is found during traversal, which test_dangling_symlink already asserts:

Find.find(dir) { |path| ... }   # => [dir, "#{dir}/broken"]

The argument check uses File.exist?, which follows the link, so a dangling one looks missing. Everywhere else the module uses File.lstat, which does not follow it. This accepts an argument that is a symlink, so both cases agree.

Paths that really do not exist still raise Errno::ENOENT; test_nonexistence ([Bug #12087]) covers that.

Find.find checked its arguments with File.exist?, which follows symbolic
links, so a dangling symlink was rejected as if it did not exist. The
link itself is a valid entry: File.lstat succeeds on it, and one found
during traversal is yielded like any other, as test_dangling_symlink
asserts.

Accept an argument that is a symlink, so passing a dangling one directly
behaves the same as finding it inside a directory. Paths that really do
not exist still raise Errno::ENOENT.

Fixes ruby#18
@carlosdanielpohlod
carlosdanielpohlod marked this pull request as ready for review September 8, 2026 23:41
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.

[bug] find() breaks if a broken link is passed as argument

1 participant

⌂ Proxy