Skip to content

Add File.readlink?#16004

Merged
straight-shoota merged 3 commits intocrystal-lang:masterfrom
straight-shoota:feat/file.readlink
Jul 22, 2025
Merged

Add File.readlink?#16004
straight-shoota merged 3 commits intocrystal-lang:masterfrom
straight-shoota:feat/file.readlink

Conversation

@straight-shoota
Copy link
Member

File.readlink? is a non-raising alternative to File.readlink which returns nil if the file doesn't exist or is not a symlink.

if bytesize == -1
if Errno.value.in?(Errno::EINVAL, Errno::ENOENT, Errno::ENOTDIR)
yield
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion (non blocking): we could simplify and boost the implementation if buf was a StaticArray(UInt8, 4096), no need for the loop and no need to allocate Bytes, only the final String.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's move that to a follow-up.

straight-shoota and others added 2 commits July 21, 2025 16:53
Co-authored-by: Julien Portalier <julien@portalier.com>
@straight-shoota straight-shoota added this to the 1.18.0 milestone Jul 21, 2025
@straight-shoota straight-shoota merged commit 835a698 into crystal-lang:master Jul 22, 2025
38 checks passed
@straight-shoota straight-shoota deleted the feat/file.readlink branch July 22, 2025 22:05
@straight-shoota
Copy link
Member Author

This caused an async merge conflict with #16002 which inadvertedly called Crystal::System::File.readlink which now has a different signature. It was never supposed to call the system method, instead we want the public method.
The root cause for this is that we're duplicating public API methods on types with the same name inside the Crystal::System namespace and calls from within that namespace implicitly target the system implementation, not the public one.

straight-shoota added a commit that referenced this pull request Jul 23, 2025
…16022)

Fixes a regression caused by simultaneous changes to the same code in #16004 and #16002 (#16004 (comment)).

The call was never supposed to go to `File.readlink` (i.e. `Crystal::System::File.readlink`) but the public method `::File.readlink`.
Now with `::File.readlink?` available from #16004, we can use that directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants