-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Deprecate std::fs::soft_link in favor of platform-specific versions #24222
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #24433) made this pull request unmergeable. Please resolve the merge conflicts. |
15ab7b4
to
72cfaae
Compare
I've rebased and updated to include the split into I don't have Windows available to build or test on, and tests for symlinks on a buildbot don't work properly as you need special permissions to create symlinks on Windows, so if it would be possible for someone to try it out and make sure that I didn't break anything on Windows I would appreciate that. |
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symlink_file => symlink ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, fixed.
Looks great, thanks @lambda! It's ok to not worry about symlink tests for windows right now. |
3c824c7
to
e9f950b
Compare
@@ -828,17 +832,20 @@ pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<( | |||
/// # Ok(()) | |||
/// # } | |||
/// ``` | |||
#[deprecated(since = "1.0.0", | |||
reason = "replaced with std::os::unix::fs::symlink and \ | |||
std::os::windows::{symlink_file, symlink_dir}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, windows::{
-> windows::fs::{
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, thanks for the catch.
I've now merged the RFC, just noticed a few nits though, but other than that r=me |
e9f950b
to
acd426b
Compare
Fixed up the nits. |
⌛ Testing commit acd426b with merge caa75f0... |
💔 Test failed - auto-win-64-nopt-t |
acd426b
to
14044c9
Compare
Added missing |
⌛ Testing commit 14044c9 with merge 1556209... |
💔 Test failed - auto-linux-64-nopt-t |
14044c9
to
1489e23
Compare
Added feature gates to doc tests, and actually ran doc tests this time to ensure they work. |
⌛ Testing commit 1489e23 with merge feb8acd... |
💔 Test failed - auto-linux-64-nopt-t |
😞 Hmm, this failure doesn't look like it's related to my change; it looks like it just hung for some unknown reason. |
@bors: retry |
On Windows, when you create a symbolic link you must specify whether it points to a directory or a file, even if it is created dangling, while on Unix, the same symbolic link could point to a directory, a file, or nothing at all. Furthermore, on Windows special privilege is necessary to use a symbolic link, while on Unix, you can generally create a symbolic link in any directory you have write privileges to. This means that it is unlikely to be able to use symbolic links purely portably; anyone who uses them will need to think about the cross platform implications. This means that using platform-specific APIs will make it easier to see where code will need to differ between the platforms, rather than trying to provide some kind of compatibility wrapper. Furthermore, `soft_link` has no precedence in any other API, so to avoid confusion, move back to the more standard `symlink` terminology. Create a `std::os::unix::symlink` for the Unix version that is destination type agnostic, as well as `std::os::windows::{symlink_file, symlink_dir}` for Windows. Because this is a stable API, leave a compatibility wrapper in `std::fs::soft_link`, which calls `symlink` on Unix and `symlink_file` on Windows, preserving the existing behavior of `soft_link`.
1489e23
to
3cc84ef
Compare
I realized that the Windows doc tests were likely to fail, because I included examples in the Windows docs, but as discussed, you can't create symlinks without special privileges. I've updated the Windows example to use |
Implement [RFC rust-lang#1048][rfc]. On Windows, when you create a symbolic link you must specify whether it points to a directory or a file, even if it is created dangling, while on Unix, the same symbolic link could point to a directory, a file, or nothing at all. Furthermore, on Windows special privilege is necessary to use a symbolic link, while on Unix, you can generally create a symbolic link in any directory you have write privileges to. This means that it is unlikely to be able to use symbolic links purely portably; anyone who uses them will need to think about the cross platform implications. This means that using platform-specific APIs will make it easier to see where code will need to differ between the platforms, rather than trying to provide some kind of compatibility wrapper. Furthermore, `soft_link` has no precedence in any other API, so to avoid confusion, move back to the more standard `symlink` terminology. Create a `std::os::unix::symlink` for the Unix version that is destination type agnostic, as well as `std::os::windows::{symlink_file, symlink_dir}` for Windows. Because this is a stable API, leave a compatibility wrapper in `std::fs::soft_link`, which calls `symlink` on Unix and `symlink_file` on Windows, preserving the existing behavior of `soft_link`. [rfc]: rust-lang/rfcs#1048
Implement RFC #1048.
On Windows, when you create a symbolic link you must specify whether it
points to a directory or a file, even if it is created dangling, while
on Unix, the same symbolic link could point to a directory, a file, or
nothing at all. Furthermore, on Windows special privilege is necessary
to use a symbolic link, while on Unix, you can generally create a
symbolic link in any directory you have write privileges to.
This means that it is unlikely to be able to use symbolic links purely
portably; anyone who uses them will need to think about the cross
platform implications. This means that using platform-specific APIs
will make it easier to see where code will need to differ between the
platforms, rather than trying to provide some kind of compatibility
wrapper.
Furthermore,
soft_link
has no precedence in any other API, so to avoidconfusion, move back to the more standard
symlink
terminology.Create a
std::os::unix::symlink
for the Unix version that isdestination type agnostic, as well as
std::os::windows::{symlink_file, symlink_dir}
for Windows.Because this is a stable API, leave a compatibility wrapper in
std::fs::soft_link
, which callssymlink
on Unix andsymlink_file
on Windows, preserving the existing behavior of
soft_link
.