[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#70561: ln -sfr stats the wrong file
From: |
David Leonard |
Subject: |
bug#70561: ln -sfr stats the wrong file |
Date: |
Thu, 25 Apr 2024 10:53:43 +1000 (AEST) |
User-agent: |
Alpine 2.26 (DEB 649 2022-06-02) |
(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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#70561: ln -sfr stats the wrong file,
David Leonard <=