Skip to content

Commit 3a897ba

Browse files
committed
Address code review.
1 parent 335e1ac commit 3a897ba

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
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, 5)?,
208+
path_hash = path_hash(&metadata.workspace_root, docker::PATH_HASH_SHORT)?,
209209
custom = if matches!(self, Self::File { .. }) {
210210
""
211211
} else {

src/docker/remote.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
7171
let temppath = tempdir.path();
7272
let had_symlinks = copy_dir(src, temppath, copy_symlinks, 0, |e, _| is_cachedir(e))?;
7373
warn_symlinks(had_symlinks, msg_info)?;
74-
self.copy_files(temppath, dst, msg_info)
74+
self.copy_files(&temppath.join("."), dst, msg_info)
7575
}
7676

7777
// copy files for a docker volume, for remote host support
@@ -567,7 +567,7 @@ impl QualifiedToolchain {
567567
.file_name()
568568
.expect("should be able to get toolchain name")
569569
.to_utf8()?;
570-
let toolchain_hash = path_hash(self.get_sysroot(), 5)?;
570+
let toolchain_hash = path_hash(self.get_sysroot(), PATH_HASH_SHORT)?;
571571
Ok(format!(
572572
"{VOLUME_PREFIX}{toolchain_name}-{toolchain_hash}-{commit_hash}"
573573
))
@@ -577,15 +577,15 @@ impl QualifiedToolchain {
577577
// be generated outside a rust package and run multiple times.
578578
pub fn unique_container_identifier(&self, triple: &TargetTriple) -> Result<String> {
579579
let toolchain_id = self.unique_toolchain_identifier()?;
580-
let cwd_path = path_hash(&env::current_dir()?, 5)?;
580+
let cwd_path = path_hash(&env::current_dir()?, PATH_HASH_SHORT)?;
581581
let system_time = now_as_millis()?;
582582
Ok(format!("{toolchain_id}-{triple}-{cwd_path}-{system_time}"))
583583
}
584584

585585
// unique identifier for a given mounted volume
586586
pub fn unique_mount_identifier(&self, path: &Path) -> Result<String> {
587587
let toolchain_id = self.unique_toolchain_identifier()?;
588-
let mount_hash = path_hash(path, 10)?;
588+
let mount_hash = path_hash(path, PATH_HASH_UNIQUE)?;
589589
Ok(format!("{toolchain_id}-{mount_hash}"))
590590
}
591591
}

src/docker/shared.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,13 @@ impl MountFinder {
14431443
}
14441444
}
14451445

1446+
/// Short hash for identifiers with minimal risk of collision.
1447+
pub const PATH_HASH_SHORT: usize = 5;
1448+
1449+
/// Longer hash to minimize risk of random collisions
1450+
/// Collision chance is ~10^-6
1451+
pub const PATH_HASH_UNIQUE: usize = 10;
1452+
14461453
fn path_digest(path: &Path) -> Result<const_sha1::Digest> {
14471454
let buffer = const_sha1::ConstBuffer::from_slice(path.to_utf8()?.as_bytes());
14481455
Ok(const_sha1::sha1(&buffer))

0 commit comments

Comments
 (0)