mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-24 08:53:04 +10:00
Fix local path and templating issues (#436)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user