Skip to content

Commit 85ce931

Browse files
committed
Fix the fingerprint filenames.
Fixes the regression in 1054, since previously the fingerprint file name was based off the volume name. Since the volume names rely on the system time, this ensures the fingerprints are specific for only the toolchain and the path of directory.
1 parent c0b3670 commit 85ce931

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/docker/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a> Dockerfile<'a> {
205205
"{}{package_name}:{target_triple}-{path_hash}{custom}",
206206
CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX,
207207
package_name = docker_package_name(metadata),
208-
path_hash = path_hash(&metadata.workspace_root)?,
208+
path_hash = path_hash(&metadata.workspace_root, 5)?,
209209
custom = if matches!(self, Self::File { .. }) {
210210
""
211211
} else {

src/docker/remote.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
342342
VolumeId::Keep(_) => {
343343
let parent = temp::dir()?;
344344
file::create_dir_all(&parent)?;
345-
let fingerprint = parent.join(self.container);
345+
346+
let toolchain = &self.toolchain_dirs.toolchain();
347+
let filename = toolchain.unique_mount_identifier(src)?;
348+
let fingerprint = parent.join(filename);
346349
let current = Fingerprint::read_dir(src, copy_cache)?;
347350
// need to check if the container path exists, otherwise we might
348351
// have stale data: the persistent volume was deleted & recreated.
@@ -561,7 +564,7 @@ impl QualifiedToolchain {
561564
.file_name()
562565
.expect("should be able to get toolchain name")
563566
.to_utf8()?;
564-
let toolchain_hash = path_hash(self.get_sysroot())?;
567+
let toolchain_hash = path_hash(self.get_sysroot(), 5)?;
565568
Ok(format!(
566569
"{VOLUME_PREFIX}{toolchain_name}-{toolchain_hash}-{commit_hash}"
567570
))
@@ -571,10 +574,17 @@ impl QualifiedToolchain {
571574
// be generated outside a rust package and run multiple times.
572575
pub fn unique_container_identifier(&self, triple: &TargetTriple) -> Result<String> {
573576
let toolchain_id = self.unique_toolchain_identifier()?;
574-
let cwd_path = path_hash(&env::current_dir()?)?;
577+
let cwd_path = path_hash(&env::current_dir()?, 5)?;
575578
let system_time = now_as_millis()?;
576579
Ok(format!("{toolchain_id}-{triple}-{cwd_path}-{system_time}"))
577580
}
581+
582+
// unique identifier for a given mounted volume
583+
pub fn unique_mount_identifier(&self, path: &Path) -> Result<String> {
584+
let toolchain_id = self.unique_toolchain_identifier()?;
585+
let mount_hash = path_hash(path, 10)?;
586+
Ok(format!("{toolchain_id}-{mount_hash}"))
587+
}
578588
}
579589

580590
pub(crate) fn run(

src/docker/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,11 +1417,11 @@ fn path_digest(path: &Path) -> Result<const_sha1::Digest> {
14171417
Ok(const_sha1::sha1(&buffer))
14181418
}
14191419

1420-
pub fn path_hash(path: &Path) -> Result<String> {
1420+
pub fn path_hash(path: &Path, count: usize) -> Result<String> {
14211421
Ok(path_digest(path)?
14221422
.to_string()
1423-
.get(..5)
1424-
.expect("sha1 is expected to be at least 5 characters long")
1423+
.get(..count)
1424+
.unwrap_or_else(|| panic!("sha1 is expected to be at least {count} characters long"))
14251425
.to_owned())
14261426
}
14271427

0 commit comments

Comments
 (0)