Skip to content

Commit 5a78ca9

Browse files
David Tolnayfacebook-github-bot
David Tolnay
authored andcommitted
Disambiguate fs2 extension-trait locking calls
Summary: Some `fs2::FileExt` extension-trait methods overlap with new file locking API on `std::fs::File` in Rust 1.84 (D70601924). ```lang=text,counterexample error: a method with this name may be added to the standard library in the future --> fbcode/clifoundation/cli_target/validator/src/main.rs:279:20 | 279 | cache_file.lock_shared()?; | ^^^^^^^^^^^ | = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <rust-lang/rust#48919> = help: call with fully qualified syntax `fs4::FileExt::lock_shared(...)` to keep using the current method = note: requested on the command line with `-D unstable-name-collisions` help: add `#![feature(file_lock)]` to the crate attributes to enable `std::fs::File::lock_shared` | 1 + #![feature(file_lock)] | ``` This diff (still on Rust 1.83) qualifies all the extension-trait calls so that these do not become a factor in the Rust 1.84 diff. After D70601924, it would be reasonable to drop `fs2` and `fs4` dependencies and use the standard library APIs instead. Reviewed By: diliop Differential Revision: D70676686 fbshipit-source-id: ed9dc8fa139c56e1a6f8e2fc39b923a81e8711b3
1 parent 10f9e1e commit 5a78ca9

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

hphp/hack/src/utils/hh_slog/locked_file_drain.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55

6-
use fs2::FileExt;
76
use slog::Drain;
87

98
/// Locks the file when logging. Prevents multi-process writes from mangling if
@@ -48,7 +47,7 @@ impl Drain for LockedFileDrain {
4847
};
4948

5049
// Acquiring exclusive lock
51-
while let Err(err) = file.lock_exclusive() {
50+
while let Err(err) = fs2::FileExt::lock_exclusive(&file) {
5251
match err.kind() {
5352
// This shouldn't happen often, but if it's just an
5453
// interruption, retry.
@@ -69,7 +68,7 @@ impl Drain for LockedFileDrain {
6968
}
7069

7170
// Releasing lock
72-
while let Err(err) = file.unlock() {
71+
while let Err(err) = fs2::FileExt::unlock(&file) {
7372
match err.kind() {
7473
std::io::ErrorKind::Interrupted => continue,
7574
_ => {

hphp/hack/src/utils/rust/file_rwlock.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ impl<T: serde::Serialize + for<'de> serde::Deserialize<'de>> FileRwLock<T> {
155155
tempfile::NamedTempFile::new_in(parent).path_context(&self.path, "open(O_TMPFILE)")?;
156156
#[cfg(not(target_os = "linux"))]
157157
let file = nfile.as_file_mut();
158-
use fs2::FileExt;
159-
file.lock_exclusive()
160-
.path_context(&self.path, "flock(LOCK_EX)")?;
158+
fs2::FileExt::lock_exclusive(&file).path_context(&self.path, "flock(LOCK_EX)")?;
161159

162160
// Initialize the file. The file will initially be in "state" provided as a parameter,
163161
// either present or poisoned, with different behaviors should we crash.
@@ -270,13 +268,10 @@ impl<T: serde::Serialize + for<'de> serde::Deserialize<'de>> FileRwLock<T> {
270268
};
271269

272270
// Our sequence point will be the moment we acquire the lock.
273-
use fs2::FileExt;
274271
if write {
275-
file.lock_exclusive()
276-
.path_context(&self.path, "flock(LOCK_EX)")?;
272+
fs2::FileExt::lock_exclusive(&file).path_context(&self.path, "flock(LOCK_EX)")?;
277273
} else {
278-
file.lock_shared()
279-
.path_context(&self.path, "flock(LOCKS_SH)")?;
274+
fs2::FileExt::lock_shared(&file).path_context(&self.path, "flock(LOCKS_SH)")?;
280275
}
281276

282277
// Now we have the lock, we can examine what we have in hand...
@@ -348,9 +343,7 @@ impl<T: serde::Serialize + for<'de> serde::Deserialize<'de>> FileRwLock<T> {
348343
Err(e) => Err(e).path_context(&self.path, "open(WR)"),
349344
Ok(file) => {
350345
// Our sequence point will be the moment we acquire the lock.
351-
use fs2::FileExt;
352-
file.lock_exclusive()
353-
.path_context(&self.path, "flock(LOCK_EX)")?;
346+
fs2::FileExt::lock_exclusive(&file).path_context(&self.path, "flock(LOCK_EX)")?;
354347

355348
// A stopped lockfile is represented by an empty file -- either
356349
// empty from the create(true).open() statement above at the start

0 commit comments

Comments
 (0)