Skip to content

Commit cb3e6ee

Browse files
committed
Prefix absolute file names with directory hashes to ensure name uniqueness.
1 parent a1a5b1f commit cb3e6ee

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656
#![allow(deprecated)]
5757
#![deny(missing_docs)]
5858

59-
use std::collections::HashMap;
59+
use std::collections::{hash_map, HashMap};
6060
use std::env;
6161
use std::ffi::{OsStr, OsString};
6262
use std::fmt::{self, Display, Formatter};
6363
use std::fs;
64+
use std::hash::Hasher;
6465
use std::io::{self, BufRead, BufReader, Read, Write};
6566
use std::path::{Component, Path, PathBuf};
6667
use std::process::{Child, Command, Stdio};
@@ -1014,6 +1015,21 @@ impl Build {
10141015
};
10151016
}
10161017
}
1018+
// ... and prefix the `basename` with the `dirname`'s hash
1019+
// to ensure name uniqueness.
1020+
let basename = file
1021+
.file_name()
1022+
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "file_name() failure"))?
1023+
.to_string_lossy();
1024+
let dirname = file
1025+
.parent()
1026+
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "parent() failure"))?
1027+
.to_string_lossy();
1028+
let mut hasher = hash_map::DefaultHasher::new();
1029+
hasher.write(dirname.to_string().as_bytes());
1030+
if dst.pop() {
1031+
dst.push(format!("{:016x}-{}", hasher.finish(), basename));
1032+
}
10171033
dst.with_extension("o")
10181034
} else {
10191035
dst.join(file).with_extension("o")

0 commit comments

Comments
 (0)