From: David Leonard <d+gnubugs@adaptive-enterprises.com>
To: 70561@debbugs.gnu.org
Subject: bug#70561: ln -sfr stats the wrong file
Date: Thu, 25 Apr 2024 10:53:43 +1000 (AEST) [thread overview]
Message-ID: <5pnop7o4-3p58-n169-ro73-1897n847o58r@nqncgvir-ragrecevfrf.pbz> (raw)
(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.
reply other threads:[~2024-04-25 5:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-coreutils
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5pnop7o4-3p58-n169-ro73-1897n847o58r@nqncgvir-ragrecevfrf.pbz \
--to=d+gnubugs@adaptive-enterprises.com \
--cc=70561@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).