From 1bf8899b10c066b8cbd4523f1e60761cadbd0c55 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 26 Jul 2022 21:27:41 +0200 Subject: [PATCH] Don't graft subdirectories, rely solely on source directory hashes. --- src/lib.rs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 91cfd0e37..fc505afbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -971,23 +971,8 @@ impl Build { let mut objects = Vec::new(); for file in self.files.iter() { let obj = if file.has_root() { - // If `file` is an absolute path, try to remove the part - // common with the destination directory, and graft the - // remaining part. Most common outcome would be removal - // of the home directory, next common - removal of the root - // directory. - let mut pre = dst.components(); - let mut dst = dst.clone(); - for comp in file.components() { - if comp != pre.next().unwrap_or(Component::CurDir) { - match comp { - Component::Normal(c) => dst.push(c), - _ => (), - }; - } - } - // ... and prefix the `basename` with the `dirname`'s hash - // to ensure name uniqueness. + // If `file` is an absolute path, prefix the `basename` + // with the `dirname`'s hash to ensure name uniqueness. let basename = file .file_name() .ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "file_name() failure"))? @@ -998,10 +983,8 @@ impl Build { .to_string_lossy(); let mut hasher = hash_map::DefaultHasher::new(); hasher.write(dirname.to_string().as_bytes()); - if dst.pop() { - dst.push(format!("{:016x}-{}", hasher.finish(), basename)); - } - dst.with_extension("o") + dst.join(format!("{:016x}-{}", hasher.finish(), basename)) + .with_extension("o") } else { dst.join(file).with_extension("o") };