Skip to content

ln: ln -s -f fails with ENOTDIR when the destination's parent path is a symlink #14795

Description

@varranvar

ln -s -f fails with ENOTDIR when the destination's parent path is a symlink. This is a regression in 0.12.0.

$ mkdir -p modules dst                                                                                 
$ ln -s -f "$PWD/modules" dst/ucc    # ok: dst/ucc -> modules                                          
$ ln -s -f "$PWD/modules" dst/ucc    # ok, but creates modules/modules -> modules    
$ ln -s -f "$PWD/modules" dst/ucc    # fails                                                           
ln: failed to create symbolic link 'dst/ucc/modules': Not a directory                                  

Expected (GNU, uutils 0.11.0): The third command succeeds. The forced replacement unlinks and recreates the link.

The cause seems to be replace_link() introduced in #14623. In replace_link(), the initial symlinkat() fails with EEXIST because modules/modules already exists, and the fallback then opens the destination's parent with O_NOFOLLOW | O_DIRECTORY. Since the parent ends in a symlink, the open fails with ENOTDIR.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions