Skip to content

Commit 231505c

Browse files
committed
refactor(locking): Make disabling locking on NFS mounts explict
1 parent 6c1b610 commit 231505c

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/cargo/core/compiler/layout.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
104104
use crate::core::Workspace;
105105
use crate::core::compiler::CompileTarget;
106+
use crate::util::flock::is_on_nfs_mount;
106107
use crate::util::{CargoResult, FileLock};
107108
use cargo_util::paths;
108109
use std::path::{Path, PathBuf};
@@ -152,17 +153,21 @@ impl Layout {
152153
// For now we don't do any more finer-grained locking on the artifact
153154
// directory, so just lock the entire thing for the duration of this
154155
// compile.
155-
let artifact_dir_lock =
156-
dest.open_rw_exclusive_create(".cargo-lock", ws.gctx(), "build directory")?;
156+
let artifact_dir_lock = if is_on_nfs_mount(root.as_path_unlocked()) {
157+
None
158+
} else {
159+
Some(dest.open_rw_exclusive_create(".cargo-lock", ws.gctx(), "artifact directory")?)
160+
};
157161

158-
let build_dir_lock = if root != build_root {
162+
let build_dir_lock = if root == build_root || is_on_nfs_mount(build_root.as_path_unlocked())
163+
{
164+
None
165+
} else {
159166
Some(build_dest.open_rw_exclusive_create(
160167
".cargo-lock",
161168
ws.gctx(),
162169
"build directory",
163170
)?)
164-
} else {
165-
None
166171
};
167172
let root = root.into_path_unlocked();
168173
let build_root = build_root.into_path_unlocked();
@@ -222,7 +227,7 @@ pub struct ArtifactDirLayout {
222227
timings: PathBuf,
223228
/// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
224229
/// struct is `drop`ped.
225-
_lock: FileLock,
230+
_lock: Option<FileLock>,
226231
}
227232

228233
impl ArtifactDirLayout {

src/cargo/util/flock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn acquire(
427427
}
428428

429429
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
430-
fn is_on_nfs_mount(path: &Path) -> bool {
430+
pub fn is_on_nfs_mount(path: &Path) -> bool {
431431
use std::ffi::CString;
432432
use std::mem;
433433
use std::os::unix::prelude::*;
@@ -445,7 +445,7 @@ fn is_on_nfs_mount(path: &Path) -> bool {
445445
}
446446

447447
#[cfg(any(not(target_os = "linux"), target_env = "musl"))]
448-
fn is_on_nfs_mount(_path: &Path) -> bool {
448+
pub fn is_on_nfs_mount(_path: &Path) -> bool {
449449
false
450450
}
451451

src/cargo/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod dependency_queue;
4242
pub mod diagnostic_server;
4343
pub mod edit_distance;
4444
pub mod errors;
45-
mod flock;
45+
pub mod flock;
4646
pub mod frontmatter;
4747
pub mod graph;
4848
mod hasher;

0 commit comments

Comments
 (0)