Skip to content

touch -r: dangling symlink reference is accepted #9703

@sylvestre

Description

@sylvestre

Component

touch

Description

When touch is asked to follow symlinks (default), stat() falls back from fs::metadata() to
fs::symlink_metadata() on any error.

fs::metadata(path).or_else(|_| fs::symlink_metadata(path))

This means touch -r <ref> <dst> will silently accept a dangling symlink reference and use the symlink’s
own timestamps, instead of erroring like GNU.

Test / Reproduction Steps

mkdir -p /tmp/touch-audit
cd /tmp/touch-audit
ln -s /nope ref
rm -f out

# uutils: succeeds, creates "out"
# GNU: fails (reference is inaccessible)
touch -r ref out; echo "exit:$?"; ls -la out

Impact

Hides real failures for -r/--reference and can make scripts behave as if the reference file was valid.
Also breaks GNU compatibility.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions