On 16/11/2026 22:04, Pádraig Brady wrote:
On 16/11/2026 20:18, Paul Eggert wrote:
On 2026-11-16 08:02, Bayes Coratio wrote:
Would such a change be acceptable? If so, I can try to prepare a patch with a
test.
I think POSIX requires the symlink to be followed in this case,
unfortunately.
Yes I agree.
Though the final rmdir behavior is a bit confusing / inconsistent.
The warning suppression with -f is not appropriate as that's
really only allowed for missing items, not items of the wrong type.
Also it's inconsistent to leave the target directory in place.
We could avoid both issues by having the final rmdir,
remove the target directory rather than the symlink.
I checked FreeBSD, and this is what it does.
After searching a bit more, I should add that the FreeBSD kernel
handles this transparently. Also we have this comment on an
rmdir test in gnulib:
/* Test symlink behavior. Specifying trailing slash should remove
referent directory (POSIX), or cause ENOTDIR failure (Linux), but
not touch symlink. We prefer the Linux behavior for its
intuitiveness (especially compared to rmdir("symlink-to-file/")),
but not enough to penalize POSIX systems with an rpl_rmdir. */
Now that's rmdir(2) not rm(1), so I still think we could
change things here as I suggested above.
Perhaps something along the lines of:
if (errno == ENOTDIR) {
char *resolved = canonicalize_filename_mode (ent->fts_path, CAN_EXISTING);
if (resolved && SAME_INODE (lstat(resolved), fts_statp)))
unlinkat (AT_FDCWD, resolved, flag);
}
cheers,
Padraig