-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Clarify behavior of std::fs::hard_link when second path already exists. #130117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@rustbot claim |
The code responsible for this redirects to fs_imp::link which is defined up top as Perhaps a better way is to write a small program to do the hard link creation with an existing file at the link location and run that on a few platforms and see what happens. Report back with your findings and maybe it will then be clear what behavior to document. |
Rollup merge of rust-lang#135415 - Harshit933:hard-link-error, r=ChrisDenton Add `File already exists` error doc to `hard_link` function ## Description If the link path already exists, the error `AlreadyExists` is returned. This commit adds this error to the docs. I tested it with the current rust master version, this error was returned when there is already a link for the file is present. This was the error returned: ``` [harshit:../Desktop/rust_compiler_testing/hard_link (master|…5)] cargo +stage1 run Compiling hard_link v0.1.0 (/home/harshit/Desktop/rust_compiler_testing/hard_link) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s Running `target/debug/hard_link` Err(Os { code: 17, kind: AlreadyExists, message: "File exists" }) ``` This is my first PR on rust, any suggestions on which issue I can take next are most welcome 😄 Fixes rust-lang#130117
…sDenton Add `File already exists` error doc to `hard_link` function ## Description If the link path already exists, the error `AlreadyExists` is returned. This commit adds this error to the docs. I tested it with the current rust master version, this error was returned when there is already a link for the file is present. This was the error returned: ``` [harshit:../Desktop/rust_compiler_testing/hard_link (master|…5)] cargo +stage1 run Compiling hard_link v0.1.0 (/home/harshit/Desktop/rust_compiler_testing/hard_link) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s Running `target/debug/hard_link` Err(Os { code: 17, kind: AlreadyExists, message: "File exists" }) ``` This is my first PR on rust, any suggestions on which issue I can take next are most welcome 😄 Fixes rust-lang#130117
Location
Documentation of the
std::fs::hard_link
function, e.g. https://doc.rust-lang.org/std/fs/fn.hard_link.htmlSummary
The function currently doesn't specify what happens if the second parameter (
link
/ "the destination") already exists.The note for unix systems and linux's man pages lead me to believe it will return an error in this case, but I don't think one should have to read linux man pages to determine the behavior of a rust function and it's not obvious if this is the intended rust behavior across platforms or if the behavior would be platform-specific.
Assuming it's not platform-specific, I think it'd be sufficient to add a bullet point to the
# Errors
section as a second documented error case.The text was updated successfully, but these errors were encountered: