diff --git a/crates/puffin-cache/src/canonical_url.rs b/crates/puffin-cache/src/canonical_url.rs index d009adcfb..62868f5f2 100644 --- a/crates/puffin-cache/src/canonical_url.rs +++ b/crates/puffin-cache/src/canonical_url.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Formatter}; use std::hash::{Hash, Hasher}; use std::ops::Deref; @@ -85,6 +86,12 @@ impl Hash for CanonicalUrl { } } +impl std::fmt::Display for CanonicalUrl { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} + /// Like [`CanonicalUrl`], but attempts to represent an underlying source repository, abstracting /// away details like the specific commit or branch, or the subdirectory to build within the /// repository. diff --git a/crates/puffin-distribution/src/source_dist.rs b/crates/puffin-distribution/src/source_dist.rs index f95150862..455843486 100644 --- a/crates/puffin-distribution/src/source_dist.rs +++ b/crates/puffin-distribution/src/source_dist.rs @@ -653,7 +653,8 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> { // Avoid races between different processes, too. let lock_dir = git_dir.join("locks"); fs::create_dir_all(&lock_dir).await?; - let _lock = LockedFile::acquire(lock_dir.join(digest(&CanonicalUrl::new(url))))?; + let canonical_url = CanonicalUrl::new(url); + let _lock = LockedFile::acquire(lock_dir.join(digest(&canonical_url)), &canonical_url)?; let DirectGitUrl { url, subdirectory } = DirectGitUrl::try_from(url).map_err(SourceDistError::Git)?; diff --git a/crates/puffin-fs/src/lib.rs b/crates/puffin-fs/src/lib.rs index 301cc79d9..6e35780f3 100644 --- a/crates/puffin-fs/src/lib.rs +++ b/crates/puffin-fs/src/lib.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::path::{Path, PathBuf}; use fs2::FileExt; @@ -99,14 +100,15 @@ pub fn directories(path: impl AsRef) -> impl Iterator { pub struct LockedFile(fs_err::File); impl LockedFile { - pub fn acquire(path: impl AsRef) -> Result { + pub fn acquire(path: impl AsRef, resource: impl Display) -> Result { let file = fs_err::File::create(path.as_ref())?; match file.file().try_lock_exclusive() { Ok(()) => Ok(Self(file)), Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => { warn_user!( - "Waiting to acquire lock on {}", - path.as_ref().parent().unwrap_or(path.as_ref()).display() + "Waiting to acquire lock for {} (lockfile: {})", + resource, + path.as_ref().display() ); file.file().lock_exclusive()?; Ok(Self(file)) diff --git a/crates/puffin-interpreter/src/virtual_env.rs b/crates/puffin-interpreter/src/virtual_env.rs index edbaeb099..ed33f2e1a 100644 --- a/crates/puffin-interpreter/src/virtual_env.rs +++ b/crates/puffin-interpreter/src/virtual_env.rs @@ -104,7 +104,7 @@ impl Virtualenv { /// Lock the virtual environment to prevent concurrent writes. pub fn lock(&self) -> Result { - LockedFile::acquire(self.root.join(".lock")) + LockedFile::acquire(self.root.join(".lock"), self.root.display()) } }