Skip to content

Do not follow symlinks in File.rm_rf/1 with a trailing separator - #16044

Closed
bmalum wants to merge 1 commit into
elixir-lang:mainfrom
bmalum:fix/rm-rf-symlink-trailing-separator
Closed

bmalum wants to merge 1 commit into
elixir-lang:mainfrom
bmalum:fix/rm-rf-symlink-trailing-separator

Conversation

@bmalum

@bmalum bmalum commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

A trailing separator makes the operating system resolve a symlink in the last path component, so lstat reports a directory for link/. File.rm_rf/1 then listed the link target, removed every entry inside it and, on some systems, the target directory itself, even though the documentation states that symlinks are not followed.

Strip trailing separators from the path before inspecting it, so the link itself is removed. Paths inside the tree were already normalized by Path.join/2, so only the top-level entry changes.

A trailing separator makes the operating system resolve a symlink in
the last path component, so lstat reports a directory for "link/".
File.rm_rf/1 then listed the link target, removed every entry inside
it and, on some systems, the target directory itself, even though the
documentation states that symlinks are not followed.

Strip trailing separators from the path before inspecting it, so the
link itself is removed. Paths inside the tree were already normalized
by Path.join/2, so only the top-level entry changes.

Assisted-by: Kiro:claude-fable-5.1
@josevalim josevalim closed this in 5c48195 Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant