Merge pull request #138 from levkk/levkk-fix-filename-conflict

Fix filename conflict
This commit is contained in:
Vince Pike 2023-10-22 04:54:44 -04:00 committed by GitHub
commit ef79697c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 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>>(