Skip to content

Commit 434f3db

Browse files
committed
Prefix absolute file names with directory hashes to ensure name uniqueness.
1 parent 15c8b51 commit 434f3db

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};
@@ -1039,6 +1040,21 @@ impl Build {
10391040
};
10401041
}
10411042
}
1043+
// ... and prefix the `basename` with the `dirname`'s hash
1044+
// to ensure name uniqueness.
1045+
let basename = file
1046+
.file_name()
1047+
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "file_name() failure"))?
1048+
.to_string_lossy();
1049+
let dirname = file
1050+
.parent()
1051+
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "parent() failure"))?
1052+
.to_string_lossy();
1053+
let mut hasher = hash_map::DefaultHasher::new();
1054+
hasher.write(dirname.to_string().as_bytes());
1055+
if dst.pop() {
1056+
dst.push(format!("{:016x}-{}", hasher.finish(), basename));
1057+
}
10421058
dst.with_extension("o")
10431059
} else {
10441060
dst.join(file).with_extension("o")

0 commit comments

Comments
 (0)