refactor: remove unused bootstrap hook path environment function and streamline path handling

This commit is contained in:
2026-04-04 18:23:37 -05:00
parent 09bb4667b4
commit d61d59f4f5
+9 -22
View File
@@ -13,7 +13,6 @@ use walkdir::WalkDir;
const STAGED_SCRIPTS_DIR: &str = "scripts"; const STAGED_SCRIPTS_DIR: &str = "scripts";
const DEFERRED_HOOKS_FILE_REL: &str = "var/lib/depot/deferred-hooks.tsv"; const DEFERRED_HOOKS_FILE_REL: &str = "var/lib/depot/deferred-hooks.tsv";
const BOOTSTRAP_BIN_DIR_REL: &str = "var/lib/depot/bootstrap/bin";
const ALL_HOOKS: [Hook; 6] = [ const ALL_HOOKS: [Hook; 6] = [
Hook::PreInstall, Hook::PreInstall,
Hook::PostInstall, Hook::PostInstall,
@@ -373,14 +372,6 @@ fn should_bootstrap_host_shell(should_chroot: bool, is_root: bool, shell_exists:
should_chroot && is_root && !shell_exists should_chroot && is_root && !shell_exists
} }
fn bootstrap_hook_path_env() -> String {
format!(
"/{}:{}",
BOOTSTRAP_BIN_DIR_REL,
crate::runtime_env::safe_script_path()
)
}
fn mount_chroot_filesystems( fn mount_chroot_filesystems(
rootfs: &Path, rootfs: &Path,
bootstrap_script_path: Option<&Path>, bootstrap_script_path: Option<&Path>,
@@ -636,9 +627,15 @@ fn collect_bootstrap_tool_bindings(script_path: &Path) -> Result<Vec<BootstrapTo
} }
if let Some(host_path) = resolve_host_tool_path(&command)? { if let Some(host_path) = resolve_host_tool_path(&command)? {
let target_rel = host_path
.strip_prefix(Path::new("/"))
.with_context(|| {
format!("Expected absolute host tool path: {}", host_path.display())
})?
.to_path_buf();
bindings.insert(BootstrapToolBinding { bindings.insert(BootstrapToolBinding {
host_path, host_path,
target_rel: Path::new(BOOTSTRAP_BIN_DIR_REL).join(&command), target_rel,
}); });
} }
} }
@@ -972,11 +969,6 @@ fn run_hook_script_in_chroot(
) -> Result<std::process::ExitStatus> { ) -> Result<std::process::ExitStatus> {
let _mounts = mount_chroot_filesystems(rootfs, bootstrap_script_path)?; let _mounts = mount_chroot_filesystems(rootfs, bootstrap_script_path)?;
let rel_script = format!("./{}", rel_script.to_string_lossy()); let rel_script = format!("./{}", rel_script.to_string_lossy());
let path_env = if bootstrap_script_path.is_some() {
bootstrap_hook_path_env()
} else {
crate::runtime_env::safe_script_path().to_string()
};
let mut cmd = Command::new("chroot"); let mut cmd = Command::new("chroot");
cmd.arg(rootfs) cmd.arg(rootfs)
.arg("/bin/sh") .arg("/bin/sh")
@@ -988,7 +980,7 @@ fn run_hook_script_in_chroot(
.env("DEPOT_ROOTFS", "/") .env("DEPOT_ROOTFS", "/")
.env("DEPOT_ACTION", hook.action()) .env("DEPOT_ACTION", hook.action())
.env("DEPOT_PHASE", hook.phase()) .env("DEPOT_PHASE", hook.phase())
.env("PATH", &path_env); .env("PATH", crate::runtime_env::safe_script_path());
if quiet { if quiet {
cmd.stdout(Stdio::null()).stderr(Stdio::null()); cmd.stdout(Stdio::null()).stderr(Stdio::null());
} }
@@ -1010,11 +1002,6 @@ fn run_hook_script_contents_in_chroot(
bootstrap_script_path: Option<&Path>, bootstrap_script_path: Option<&Path>,
) -> Result<std::process::ExitStatus> { ) -> Result<std::process::ExitStatus> {
let _mounts = mount_chroot_filesystems(rootfs, bootstrap_script_path)?; let _mounts = mount_chroot_filesystems(rootfs, bootstrap_script_path)?;
let path_env = if bootstrap_script_path.is_some() {
bootstrap_hook_path_env()
} else {
crate::runtime_env::safe_script_path().to_string()
};
let mut cmd = Command::new("chroot"); let mut cmd = Command::new("chroot");
cmd.arg(rootfs) cmd.arg(rootfs)
.arg("/bin/sh") .arg("/bin/sh")
@@ -1023,7 +1010,7 @@ fn run_hook_script_contents_in_chroot(
.env("DEPOT_ROOTFS", "/") .env("DEPOT_ROOTFS", "/")
.env("DEPOT_ACTION", hook.action()) .env("DEPOT_ACTION", hook.action())
.env("DEPOT_PHASE", hook.phase()) .env("DEPOT_PHASE", hook.phase())
.env("PATH", &path_env) .env("PATH", crate::runtime_env::safe_script_path())
.stdin(Stdio::piped()); .stdin(Stdio::piped());
if quiet { if quiet {
cmd.stdout(Stdio::null()).stderr(Stdio::null()); cmd.stdout(Stdio::null()).stderr(Stdio::null());