refactor: remove deferred hook handling from lifecycle script execution
This commit is contained in:
+6
-39
@@ -270,7 +270,6 @@ pub fn run_hook_if_present(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HookRunOutcome::Deferred => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@@ -278,7 +277,6 @@ pub fn run_hook_if_present(
|
|||||||
|
|
||||||
enum HookRunOutcome {
|
enum HookRunOutcome {
|
||||||
Ran(std::process::ExitStatus),
|
Ran(std::process::ExitStatus),
|
||||||
Deferred,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -432,21 +430,12 @@ fn run_script_with_rootfs_context(
|
|||||||
return Ok(HookRunOutcome::Ran(status));
|
return Ok(HookRunOutcome::Ran(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post hooks can be deferred until the target shell exists and chroot
|
crate::log_warn!(
|
||||||
// execution is available.
|
"Running lifecycle hook {} for {} without chroot because {} has no /bin/sh",
|
||||||
if matches!(
|
hook.canonical_name(),
|
||||||
hook,
|
pkg_name,
|
||||||
Hook::PostInstall | Hook::PostUpdate | Hook::PostRemove
|
rootfs.display()
|
||||||
) {
|
);
|
||||||
enqueue_deferred_hook(rootfs, pkg_name, hook, rel)?;
|
|
||||||
crate::log_warn!(
|
|
||||||
"Deferred lifecycle hook {} for {} until {} has /bin/sh",
|
|
||||||
hook.canonical_name(),
|
|
||||||
pkg_name,
|
|
||||||
rootfs.display()
|
|
||||||
);
|
|
||||||
return Ok(HookRunOutcome::Deferred);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback (non-root / no rootfs shell / script outside rootfs):
|
// Fallback (non-root / no rootfs shell / script outside rootfs):
|
||||||
@@ -595,28 +584,6 @@ fn write_deferred_hooks(path: &Path, hooks: &[DeferredHook]) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enqueue_deferred_hook(
|
|
||||||
rootfs: &Path,
|
|
||||||
pkg_name: &str,
|
|
||||||
hook: Hook,
|
|
||||||
script_rel: &Path,
|
|
||||||
) -> Result<()> {
|
|
||||||
let path = deferred_hooks_file(rootfs);
|
|
||||||
let mut hooks = read_deferred_hooks(&path)?;
|
|
||||||
if hooks
|
|
||||||
.iter()
|
|
||||||
.any(|h| h.pkg_name == pkg_name && h.hook == hook && h.script_rel == script_rel)
|
|
||||||
{
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
hooks.push(DeferredHook {
|
|
||||||
pkg_name: pkg_name.to_string(),
|
|
||||||
hook,
|
|
||||||
script_rel: script_rel.to_path_buf(),
|
|
||||||
});
|
|
||||||
write_deferred_hooks(&path, &hooks)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempt to run deferred lifecycle hooks for this rootfs once.
|
/// Attempt to run deferred lifecycle hooks for this rootfs once.
|
||||||
///
|
///
|
||||||
/// Deferred hooks are best-effort: failures are kept in queue for later retry.
|
/// Deferred hooks are best-effort: failures are kept in queue for later retry.
|
||||||
|
|||||||
Reference in New Issue
Block a user