Preserve CLI template inputs when output is a hard link

Compare device and inode on Linux alongside existing path checks. Cover
template and values aliases with input-preservation and diagnostic checks.
Sort the existing footage test's expected paths for temporary-directory portability.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
sanyamsingh001
2026-10-14 02:14:42 +10:00
co-authored by Codex
parent 549e9d8251
commit e52ce29579
3 changed files with 55 additions and 4 deletions
+14 -1
View File
@@ -36,7 +36,20 @@ pub(super) fn validate(cmd: &str, args: &Args) -> Result<(), Failure> {
{
for input in ["--template", "--values"] {
if let Some(path) = args.opt(input)
&& std::fs::canonicalize(path).is_ok_and(|path| path == output)
&& std::fs::canonicalize(path).is_ok_and(|path| {
if path == output {
return true;
}
#[cfg(target_os = "linux")]
{
use std::os::unix::fs::MetadataExt;
// Distinct canonical paths can still name the same file through hard links.
if let (Ok(input), Ok(output)) = (std::fs::metadata(&path), std::fs::metadata(&output)) {
return input.dev() == output.dev() && input.ino() == output.ino();
}
}
false
})
{
return Err(Failure::Error(format!("--out {out} would overwrite {input} {path}")));
}