Skip to content

ln: refuse to replace a directory with --backup, -f or -i - #15888

Merged
cakebaker merged 1 commit into
uutils:mainfrom
0anes0:ln-backup-refuse-directory
Oct 29, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
0anes0:ln-backup-refuse-directory

Conversation

@0anes0

@0anes0 0anes0 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

With -b, -f or -i, ln moved an existing directory at the link name aside (or failed with "Is a directory") instead of refusing like GNU does with "cannot overwrite directory". It now checks for a real directory before backing up or prompting; a symlink to a directory is still backed up. Fixes #15788.

AI-assisted; reviewed and tested by me.

With a backup option, ln renamed an existing directory at the link name
to its backup name and created the link in its place, exiting 0. GNU ln
refuses with "cannot overwrite directory" and leaves it untouched; it
does the same for -f and -i, where uutils failed with "Is a directory"
(after a prompt for -i).

Check for a real directory before backing up or prompting. A symlink to
a directory is still backed up as a link, as GNU does. Plain ln is
unchanged and still reports "File exists".

Fixes uutils#15788
@0anes0
0anes0 force-pushed the ln-backup-refuse-directory branch from c649054 to 4414bdf Compare October 27, 2026 11:31
@cakebaker
cakebaker merged commit f499c72 into uutils:main Oct 29, 2026
99 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks for your PR!

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.

ln: --backup replaces an existing directory with the link; GNU refuses

2 participants