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

Implement file_lock feature #130999

Merged
merged 4 commits into from
Nov 11, 2024
Merged

Implement file_lock feature #130999

merged 4 commits into from
Nov 11, 2024

Conversation

cberner
Copy link
Contributor

@cberner cberner commented Sep 28, 2024

This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag

This is the initial implementation of #130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2

@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joboet (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added O-hermit Operating System: Hermit O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 28, 2024
@Noratrieb
Copy link
Member

Thank you for the PR! This PR contains a public library API change, which should follow the proper process of creating an ACP first: https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html
Use @rustbot ready when your ACP has been accepeted.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 29, 2024
@deltragon
Copy link
Contributor

@Noratrieb If I understand correctly, this already has an accepted ACP in rust-lang/libs-team#412

@cberner
Copy link
Contributor Author

cberner commented Sep 29, 2024

@ChrisDenton ah thanks! I changed it

@Noratrieb Yep, it has already been accepted in rust-lang/libs-team#412

@cberner
Copy link
Contributor Author

cberner commented Sep 29, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 29, 2024
library/std/src/fs.rs Outdated Show resolved Hide resolved
@bjorn3
Copy link
Member

bjorn3 commented Sep 29, 2024

Should this document which exact mechanism is used on each platform? I believe some platforms have multiple advisory lock mechanisms that don't affect each other. On such platforms switching mechanism in a future rust version would prevent the locks from being effective if you ever mix binaries compiled using different rustc versions.

@cberner
Copy link
Contributor Author

cberner commented Sep 29, 2024

Should this document which exact mechanism is used on each platform? I believe some platforms have multiple advisory lock mechanisms that don't affect each other. On such platforms switching mechanism in a future rust version would prevent the locks from being effective if you ever mix binaries compiled using different rustc versions.

Ah yes, good idea. I added that

///
/// This function currently corresponds to the `flock` function on Unix with the `LOCK_EX` flag,
/// and the `LockFileEx` function on Windows with the `LOCKFILE_EXCLUSIVE_LOCK` flag. Note that,
/// this [may change in the future][changes].
Copy link
Member

Choose a reason for hiding this comment

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

It must not change for programs compiled with different rustc versions to interoperate wrt locking, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I included may change in the future because that language is used in all the other places that Platform-specific behavior is documented, that I could find. Is there guidance on when to include or not include it?

It seems appropriate to include it to me, because the implementation can be changed and still interoperate. For example, LockFile can be called instead of LockFileEx in the case of lock() and lock_shared(). Similarly, you can imagine that a new syscall might be added to Unix and/or Windows which can be used as an alternative.

@cberner
Copy link
Contributor Author

cberner commented Oct 11, 2024

Just wanted to check in on this PR. @bjorn3 , @ChrisDenton anything I can do to help move it forward?

@cberner cberner force-pushed the flock_pr branch 2 times, most recently from 2744f79 to 84982e5 Compare October 13, 2024 23:01
@rustbot
Copy link
Collaborator

rustbot commented Oct 13, 2024

These commits modify the library/Cargo.lock file. Unintentional changes to library/Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and
unlock() to File gated behind the file_lock feature flag
@cberner cberner requested a review from joboet November 8, 2024 04:11
@cberner
Copy link
Contributor Author

cberner commented Nov 8, 2024

Hey @joboet just wanted to checkin on this PR. Any additional changes/tests you'd like to see?

Copy link
Member

@joboet joboet left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. This looks mostly fine!

library/std/src/sys/pal/windows/fs.rs Outdated Show resolved Hide resolved
library/std/src/sys/pal/windows/fs.rs Outdated Show resolved Hide resolved
library/std/src/sys/pal/windows/fs.rs Outdated Show resolved Hide resolved
library/std/src/sys/pal/windows/fs.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 8, 2024
@cberner cberner requested a review from joboet November 8, 2024 17:41
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 8, 2024
@cberner
Copy link
Contributor Author

cberner commented Nov 8, 2024

@joboet no worries, thanks for the comments! I've addressed them

@joboet
Copy link
Member

joboet commented Nov 11, 2024

Great, thank you!
@bors r+

@bors
Copy link
Contributor

bors commented Nov 11, 2024

📌 Commit 9330786 has been approved by joboet

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2024
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#129627 (Ensure that tail expr receive lifetime extension)
 - rust-lang#130999 (Implement file_lock feature)
 - rust-lang#132873 (handle separate prefixes in clippy rules)
 - rust-lang#132891 (Remove `rustc_session::config::rustc_short_optgroups`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2024
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#129627 (Ensure that tail expr receive lifetime extension)
 - rust-lang#130999 (Implement file_lock feature)
 - rust-lang#132873 (handle separate prefixes in clippy rules)
 - rust-lang#132891 (Remove `rustc_session::config::rustc_short_optgroups`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 95175f8 into rust-lang:master Nov 11, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 11, 2024
Rollup merge of rust-lang#130999 - cberner:flock_pr, r=joboet

Implement file_lock feature

This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag

This is the initial implementation of rust-lang#130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
Implement file_lock feature

This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag

This is the initial implementation of rust-lang#130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#129627 (Ensure that tail expr receive lifetime extension)
 - rust-lang#130999 (Implement file_lock feature)
 - rust-lang#132873 (handle separate prefixes in clippy rules)
 - rust-lang#132891 (Remove `rustc_session::config::rustc_short_optgroups`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-hermit Operating System: Hermit O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants