fix(nix): share a native runtime layout across packages

This commit is contained in:
Kevin Yue committed 2026-10-07 18:17:56 +08:00
1 parent 673cf464b0
commit 0e444236d9
11 files changed
+238 -207

No files matched your search

+4 -4
View File
@@ -435,22 +435,22 @@ impl VpnBuilder {
self
}
fn determine_script(&self) -> Result<&str, VpnError> {
fn determine_script(&self) -> Result<String, VpnError> {
match &self.script {
Some(script) => {
if self.script_is_path && !std::path::Path::new(script).exists() {
return Err(VpnError::new(format!("VPN script does not exist: {script}")));
}
check_executable(script).map_err(|e| VpnError::new(e.to_string()))?;
Ok(script)
Ok(script.clone())
}
None => find_vpnc_script().ok_or_else(|| VpnError::new(String::from("Failed to find vpnc-script"))),
}
}
pub fn build(self) -> Result<Vpn, VpnError> {
let script = self.determine_script()?.to_owned();
let script = if self.script_is_path {
let script = self.determine_script()?;
let script = if self.script_is_path || self.script.is_none() {
shell_quote_path(&script)
} else {
script
+26 -2
View File
@@ -30,8 +30,18 @@ fn find_executable(locations: &[&'static str]) -> Option<&'static str> {
None
}
pub fn find_vpnc_script() -> Option<&'static str> {
find_executable(VPNC_SCRIPT_LOCATIONS)
pub fn find_vpnc_script() -> Option<String> {
if let Some(path) = std::env::var_os("GP_VPNC_SCRIPT").filter(|path| !path.is_empty()) {
return configured_script(Path::new(&path));
}
find_executable(VPNC_SCRIPT_LOCATIONS).map(str::to_owned)
}
fn configured_script(path: &Path) -> Option<String> {
if path.is_absolute() && path.is_file() && path.is_executable() {
return path.to_str().map(str::to_owned);
}
None
}
/// If file exists, check if it is executable
@@ -47,3 +57,17 @@ pub fn check_executable(file: &str) -> Result<(), io::Error> {
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn configured_script_requires_an_absolute_executable_path() {
assert_eq!(configured_script(Path::new("/bin/sh")), Some("/bin/sh".to_owned()));
assert!(configured_script(Path::new("bin/sh")).is_none());
assert!(configured_script(Path::new("/missing-openconnect-vpnc-script")).is_none());
assert!(configured_script(Path::new("/etc/passwd")).is_none());
assert!(configured_script(Path::new("/tmp")).is_none());
}
}