coreutils
coreutils copied to clipboard
touch: Respect -h when getting metadata
Currently, if the stat function in the touch crate is used on a symlink, it will first try to get the metadata of the destination, even if the follow parameter is false. It will not get the metadata of the symlink itself if the symlink is not broken. It should now check follow first.
Minor change: the failed to get attributes for {path} context isn't currently being added to the error if the first fs::metadata call fails and follow is true. But this PR makes it so all errors have that context added to them. However, at some point in the past, it seems like all errors had that context added to them, so I figured it'd be fine (@tertsdiepraam tracked down this commit fixing an earlier issue).
The tests I added should maybe not run on FreeBSD because there's apparently an issue with nanoseconds or something? I have no idea what the difference there is, but I figured I'd set the nanoseconds field to 0 and let the CI run, just in case that works. Never mind, I added #[cfg(not(target_os = "freebsd"))] since there's not much chance of the specific behavior being tested here being different on FreeBSD.