Skip to content

remove_tree("link/") with a trailing slash follows the symlink on macOS/Linux and empties its target #1951

Closed

Description

@ehartford

Found reviewing #1863. The POSIX remove_tree walks with lstat and never enters a symlink — except when the top path ends in /: lstat("link/") resolves the link, so the target directory is emptied.

Verified on main (installed with, macOS): a scratch program with target/keep.txt, ln -s target link, then remove_tree("link/") → rc 0, link gone, keep.txt gone.

#1863 fixes the equivalent case on Windows (it strips trailing separators before the reparse-point query), so after it merges Windows is stricter than macOS/Linux. Fix: strip trailing separators from the top path before the lstat in rt/darwin*.w and rt/linux_*.w; a behavior test with a symlink + trailing slash showing the target survives.

Activity

  1. added
    bug
    on Oct 2, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 3044b9c (stack #1979, battery green on 029574d). rt_remove_tree strips the top path's trailing separators before lstat on darwin/linux; behav_1951_remove_tree_symlink_trailing_slash.w red→green.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions