(resend) When analyzing file accesses with strace, I noticed that ln stats an unrelated file. This only happens with the opions -sfr and when the dest symlink already exists.
Here's a reproduction script: # setup mkdir -p a b > b/x ln -fs anything a/x # ln -sfr b/x a/x strace -o trace.out --decode-fds=path -e %file \ src/ln -sfr b/x a/x test $(readlink a/x) = ../b/x grep stat trace.out The invalid stat that happens is: newfstatat(AT_FDCWD</tmp/lnbug>, "../b/x", 0x7ffdb94a0270, 0) = -1 ENOENT (No such file or directory) The cause seems to be in src/ln.c's do_link() where the `source` "b/x" is converted to "../b/x" by if (relative) source = rel_source = convert_abs_rel (source, dest); and then the test to see if deleting the destination file would delete the source works by checking hard links on the source. if (source_status != 0) source_status = stat (source, &source_stats); Except that -r made source relative to the dest directory.