Description
Location
https://doc.rust-lang.org/stable/std/fs/fn.remove_file.html
Summary
The documentation for std::fs::remove_file()
states:
Removes a file from the filesystem.
[...]
This function currently corresponds to the unlink function on Unix. On Windows, DeleteFile is used or CreateFileW and SetInformationByHandle for readonly files. Note that, this may change in the future.
As noted, the implementation details may changed in the future. It is not mentioned whether or not this removes the symlink link, or the target, or whether this is platform-specific.
At the moment, both unlink
1 and DeleteFile
2 remove the link, not the target. The popular symlink crate has been relying on this behaviour for over 8 years.
Is this behaviour part of the API contract?
Footnotes
-
https://www.man7.org/linux/man-pages/man2/unlink.2.html#DESCRIPTION
If the name referred to a symbolic link, the link is removed.
-
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-deletefile#remarks
If the path points to a symbolic link, the symbolic link is deleted, not the target.