Skip to content
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

Merged
merged 1 commit into from
Apr 22, 2015

Conversation

lambda
Copy link
Contributor

@lambda lambda commented Apr 9, 2015

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 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.

@rust-highfive
Copy link
Collaborator

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@bors
Copy link
Contributor

bors commented Apr 15, 2015

☔ The latest upstream changes (presumably #24433) made this pull request unmergeable. Please resolve the merge conflicts.

@lambda lambda force-pushed the rename-soft-link-to-symlink branch from 15ab7b4 to 72cfaae Compare April 15, 2015 17:19
@lambda
Copy link
Contributor Author

lambda commented Apr 15, 2015

I've rebased and updated to include the split into std::os::unix::symlink and std::os::windows::{symlink_file, symlink_dir} per the latest discussion on rust-lang/rfcs#1048.

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.

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned huonw Apr 15, 2015
/// # Ok(())
/// # }
/// ```
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symlink_file => symlink ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, fixed.

@alexcrichton
Copy link
Member

Looks great, thanks @lambda! It's ok to not worry about symlink tests for windows right now.

@lambda lambda force-pushed the rename-soft-link-to-symlink branch 2 times, most recently from 3c824c7 to e9f950b Compare April 15, 2015 18:00
@@ -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}")]
Copy link
Member

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::{

Copy link
Contributor Author

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.

@alexcrichton
Copy link
Member

I've now merged the RFC, just noticed a few nits though, but other than that r=me

@lambda lambda force-pushed the rename-soft-link-to-symlink branch from e9f950b to acd426b Compare April 18, 2015 03:17
@lambda
Copy link
Contributor Author

lambda commented Apr 18, 2015

Fixed up the nits.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ acd426b

Thanks!

@bors
Copy link
Contributor

bors commented Apr 18, 2015

⌛ Testing commit acd426b with merge caa75f0...

@bors
Copy link
Contributor

bors commented Apr 18, 2015

💔 Test failed - auto-win-64-nopt-t

@lambda lambda force-pushed the rename-soft-link-to-symlink branch from acd426b to 14044c9 Compare April 18, 2015 13:15
@lambda
Copy link
Contributor Author

lambda commented Apr 18, 2015

Added missing use statement.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ 14044c9

@bors
Copy link
Contributor

bors commented Apr 18, 2015

⌛ Testing commit 14044c9 with merge 1556209...

@bors
Copy link
Contributor

bors commented Apr 18, 2015

💔 Test failed - auto-linux-64-nopt-t

@lambda lambda force-pushed the rename-soft-link-to-symlink branch from 14044c9 to 1489e23 Compare April 21, 2015 04:10
@lambda
Copy link
Contributor Author

lambda commented Apr 21, 2015

Added feature gates to doc tests, and actually ran doc tests this time to ensure they work.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ 1489e23

@bors
Copy link
Contributor

bors commented Apr 21, 2015

⌛ Testing commit 1489e23 with merge feb8acd...

@bors
Copy link
Contributor

bors commented Apr 21, 2015

💔 Test failed - auto-linux-64-nopt-t

@lambda
Copy link
Contributor Author

lambda commented Apr 21, 2015

😞 Hmm, this failure doesn't look like it's related to my change; it looks like it just hung for some unknown reason.

@alexcrichton
Copy link
Member

@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`.
@lambda lambda force-pushed the rename-soft-link-to-symlink branch from 1489e23 to 3cc84ef Compare April 21, 2015 16:14
@lambda
Copy link
Contributor Author

lambda commented Apr 21, 2015

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 ignore to prevent this. Apologies for the churn.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ 3cc84ef

No worries!

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Apr 21, 2015
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
@bors bors merged commit 3cc84ef into rust-lang:master Apr 22, 2015
@lambda lambda changed the title Rename std::fs::soft_link to std::fs::symlink Deprecate std::fs::soft_link in favor of platform-specific versions Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants