Fix local path and templating issues (#436)

This commit is contained in:
DecDuck
2026-06-30 08:25:31 +10:00
committed by GitHub
parent 38c11567ef
commit 6f74718695
4 changed files with 63 additions and 7 deletions
+38 -1
View File
@@ -1,4 +1,6 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use log::info;
use crate::error::ProcessError;
@@ -38,6 +40,41 @@ impl ParsedCommand {
.to_string();
}
pub fn make_command_absolute_if_local(&mut self, base: &Path) {
let candidate = base.join(&self.command);
if candidate.is_file() {
info!(
"resolved local command '{}' to absolute path '{}'",
self.command,
candidate.display()
);
self.command = candidate.to_string_lossy().to_string();
} else {
info!(
"command '{}' is not a local file in '{}', leaving as-is for PATH resolution",
self.command,
base.display()
);
}
}
pub fn ensure_executable(&self) -> Result<(), ProcessError> {
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
if let Ok(metadata) = std::fs::metadata(&self.command) {
let is_executable =
metadata.is_file() && metadata.permissions().mode() & 0o111 != 0;
if !is_executable {
return Err(ProcessError::NotExecutable(self.command.clone()));
}
}
}
Ok(())
}
pub fn reconstruct(self) -> String {
let mut v = vec![];
v.extend(self.env);