Fix filename conflict

This commit is contained in:
Lev 2023-10-21 14:09:00 -07:00
parent 222f69c38a
commit 4c554d1a57
2 changed files with 8 additions and 16 deletions

View File

@ -83,6 +83,8 @@ impl Compiler {
let mut f = fs::File::create(output)
.chain_err(|| format!("Failed to create artifact: {:?}", output))?;
writeln!(f, "// Template compiled from: {}", input.display())
.chain_err(|| format!("Failed to write artifact into {:?}", output))?;
writeln!(f, "{}", rustfmt_block(&*string).unwrap_or(string))
.chain_err(|| format!("Failed to write artifact into {:?}", output))?;
drop(f);

View File

@ -105,25 +105,14 @@ fn resolve_template_file(path: &str, template_dirs: &[PathBuf]) -> Option<PathBu
}
fn filename_hash(path: &Path, config: &Config) -> String {
use std::fmt::Write;
let mut path_with_hash = String::with_capacity(16);
if let Some(n) = path.file_name() {
let mut filename = &*n.to_string_lossy();
if let Some(p) = filename.find('.') {
filename = &filename[..p];
}
path_with_hash.push_str(filename);
path_with_hash.push('-');
}
let mut hasher = DefaultHasher::new();
config.hash(&mut hasher);
let hash = hasher.finish();
let _ = write!(path_with_hash, "{:016x}", hash);
let config_hash = hasher.finish();
path_with_hash
path.hash(&mut hasher);
let path_hash = hasher.finish();
format!("{:016x}-{:016x}", config_hash, path_hash)
}
fn with_compiler<T, F: FnOnce(Compiler) -> Result<T, Error>>(
@ -249,6 +238,7 @@ fn derive_template_impl(tokens: TokenStream) -> Result<TokenStream, syn::Error>
let lock = Lock::new(&lock_path);
match lock {
Ok(lock) => {
let (tsource, report) = compiler.resolve_file(&input_file)?;
let output_filetime = filetime(&output_file);