-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Define fs::hard_link
to not follow symlinks.
#78026
Conversation
POSIX leaves it implementation-defined whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem.
(rust_highfive has picked a reviewer for you, use r? to override) |
What if an OS doesn't have support for this? |
Good question. |
cc @rust-lang/libs |
@rfcbot fcp merge
|
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I don't think @bjorn3's question was really answered. It seems like it happens to be the case that VxWorks and Redox's |
Would we be comfortable with wording that indicates "symlink is not followed if such a thing is possible on the platform"? I think the concern motivating the PR was that even on platforms which support the behavior we prefer for fs::hard_link, you can't count on that to be the standard library's behavior. This implies if VxWorks or Redox were to grow support for this operation later, we'd accept a change to the behavior to use it. In other words users would have the new guarantee from this PR on platforms that support it, and would continue to have the old weaker guarantee on other platforms until such time as those support it. |
I'd be happy with that language. |
Also mention that where possible, `hard_link` does not follow symlinks.
I've now updated the comments to take a "if such a thing is possible on the platform" stance. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors r+ |
📌 Commit d0178b4 has been approved by |
…olnay Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
…olnay Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
…olnay Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
…olnay Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
…olnay Define `fs::hard_link` to not follow symlinks. POSIX leaves it [implementation-defined] whether `link` follows symlinks. In practice, for example, on Linux it does not and on FreeBSD it does. So, switch to `linkat`, so that we can pick a behavior rather than depending on OS defaults. Pick the option to not follow symlinks. This is somewhat arbitrary, but seems the less surprising choice because hard linking is a very low-level feature which requires the source and destination to be on the same mounted filesystem, and following a symbolic link could end up in a different mounted filesystem. [implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
Rollup of 12 pull requests Successful merges: - rust-lang#77640 (Refactor IntErrorKind to avoid "underflow" terminology) - rust-lang#78026 (Define `fs::hard_link` to not follow symlinks.) - rust-lang#78114 (Recognize `private_intra_doc_links` as a lint) - rust-lang#78228 (Promote aarch64-unknown-linux-gnu to Tier 1) - rust-lang#78345 (Fix handling of item names for HIR) - rust-lang#78437 (BTreeMap: stop mistaking node for an orderly place) - rust-lang#78476 (fix some incorrect aliasing in the BTree) - rust-lang#78674 (inliner: Use substs_for_mir_body) - rust-lang#78748 (Implement destructuring assignment for tuples) - rust-lang#78868 (Fix tab focus on restyled switches) - rust-lang#78878 (Avoid overlapping cfg attributes when both macOS and aarch64) - rust-lang#78882 (Nicer hunk headers for rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
std: Fix test `symlink_hard_link` on Windows The test was introduced in rust-lang#78026 and fails depending on Windows version and admin rights. Other similar tests check for symlink creation permissions before doing anything, this PR performs the same check for `symlink_hard_link` as well.
Following rust-lang#78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks.
Make WASI's `hard_link` behavior match other platforms. Following rust-lang#78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks. r? `@alexcrichton`
Make WASI's `hard_link` behavior match other platforms. Following rust-lang#78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks. r? ``@alexcrichton``
Make WASI's `hard_link` behavior match other platforms. Following rust-lang#78026, `std::fs::hard_link` on most platforms does not follow symlinks. Change the WASI implementation to also not follow symlinks. r? ```@alexcrichton```
POSIX leaves it implementation-defined whether
link
follows symlinks.In practice, for example, on Linux it does not and on FreeBSD it does.
So, switch to
linkat
, so that we can pick a behavior rather thandepending on OS defaults.
Pick the option to not follow symlinks. This is somewhat arbitrary, but
seems the less surprising choice because hard linking is a very
low-level feature which requires the source and destination to be on
the same mounted filesystem, and following a symbolic link could end
up in a different mounted filesystem.