Skip to content

Commit

Permalink
Prefix absolute file names with directory hashes to ensure name uniqu…
Browse files Browse the repository at this point in the history
…eness.
  • Loading branch information
dot-asm committed Nov 3, 2022
1 parent a1a5b1f commit cb3e6ee
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
#![allow(deprecated)]
#![deny(missing_docs)]

use std::collections::HashMap;
use std::collections::{hash_map, HashMap};
use std::env;
use std::ffi::{OsStr, OsString};
use std::fmt::{self, Display, Formatter};
use std::fs;
use std::hash::Hasher;
use std::io::{self, BufRead, BufReader, Read, Write};
use std::path::{Component, Path, PathBuf};
use std::process::{Child, Command, Stdio};
Expand Down Expand Up @@ -1014,6 +1015,21 @@ impl Build {
};
}
}
// ... and 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"))?
.to_string_lossy();
let dirname = file
.parent()
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "parent() failure"))?
.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")
} else {
dst.join(file).with_extension("o")
Expand Down

0 comments on commit cb3e6ee

Please sign in to comment.