Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/cargo/util/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::io;
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Display, Path, PathBuf};

use crate::core::Verbosity;
use crate::util::errors::CargoResult;
use crate::util::style;
use crate::util::GlobalContext;
Expand Down Expand Up @@ -392,18 +393,20 @@ fn acquire(
lock_try: &dyn Fn() -> io::Result<()>,
lock_block: &dyn Fn() -> io::Result<()>,
) -> CargoResult<()> {
if cfg!(debug_assertions) {
// Force borrow to catch invalid borrows outside of contention situations
gctx.shell().verbosity();
}
let verbose = gctx.shell().verbosity() == Verbosity::Verbose;
if try_acquire(path, lock_try)? {
return Ok(());
}
let msg = format!("waiting for file lock on {}", msg);
let path = path.display();
let msg = if verbose {
Copy link
Member

Choose a reason for hiding this comment

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

Unsure if the discoverability of this behind --verobse. Personally I am fine with just printing the lock path unconditionally, though I think per our contribution policy maybe we want to discuss this in the original issue #15094?

format!("waiting for file lock on {msg} ({path})")
} else {
format!("waiting for file lock on {msg}")
};
gctx.shell()
.status_with_color("Blocking", &msg, &style::NOTE)?;

lock_block().with_context(|| format!("failed to lock file: {}", path.display()))?;
lock_block().with_context(|| format!("failed to lock file: {path}"))?;
Ok(())
}

Expand Down