Renaming the temp onto a destination that is already a link to the same
inode does nothing and returns success, so the temp name survived:
`ln -f a b` with b already hard-linked to a left a stray Cu* file.
Unlink the temp after the rename either way; on the normal path it is
already gone.
replace links atomically instead of unlinking first
Forced replacement was unlink(dst) then create. The gap lets another user
claim dst in a directory they can write to -- including a name the sticky
bit forbids them to remove -- so a privileged ln hands them a trusted name.
result() became fallible in 0d335ebad, but this Windows-only test still
compared the io::Result values directly, and io::Error is not PartialEq.
Unwrap both before comparing.
`ln -f A B` unlinked B before attempting the link, so a link that failed
for any reason other than the destination already existing (a missing
source, a directory source, a dangling symlink with -L) left B deleted.
Attempt the link first and remove an existing destination only after the
link reports EEXIST, matching GNU, so a failed link never destroys the
destination.
Fixes#14550
Signed-off-by: nagendramohan <nagendramohan1990@gmail.com>
The rest of the input only got its own split when something was left
after the patterns, or when every pattern was a line number with
--suppress-matched. GNU always ends with that split, so a suppressed
match on the last line or an offset reaching the end of the input left
one file short. A {*} regex is the exception: it has already consumed
the input by the time it stops matching.