mirror of
https://github.com/herdrdev/herdr.git
synced 2026-09-21 16:01:04 +00:00
@@ -16,7 +16,9 @@ fn registry_lock_path() -> PathBuf {
|
||||
crate::config::config_dir().join(REGISTRY_LOCK_FILE)
|
||||
}
|
||||
|
||||
fn with_registry_lock<T>(operation: impl FnOnce() -> std::io::Result<T>) -> std::io::Result<T> {
|
||||
pub(crate) fn with_registry_lock<T>(
|
||||
operation: impl FnOnce() -> std::io::Result<T>,
|
||||
) -> std::io::Result<T> {
|
||||
let lock_path = registry_lock_path();
|
||||
if let Some(parent) = lock_path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
|
||||
@@ -89,7 +89,7 @@ fn installations() -> io::Result<Vec<PathBuf>> {
|
||||
}
|
||||
|
||||
pub(crate) fn retain_startup(leases: &mut Leases, restored_cwds: &[PathBuf]) -> io::Result<()> {
|
||||
crate::persist::plugin_registry::read(|_| {
|
||||
crate::persist::plugin_registry::with_registry_lock(|| {
|
||||
for installation in installations()? {
|
||||
if leases.contains_key(&installation) {
|
||||
continue;
|
||||
@@ -300,6 +300,26 @@ mod tests {
|
||||
assert!(!restored.exists());
|
||||
assert!(!handoff.exists());
|
||||
|
||||
// Corrupt registry contents disable plugins, not the server. The
|
||||
// startup scan needs serialization, not registry deserialization.
|
||||
let registry = crate::config::config_dir().join("plugins.json");
|
||||
std::fs::write(®istry, "not json").unwrap();
|
||||
let (_tx, rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let app = crate::app::App::try_new(
|
||||
&crate::config::Config::default(),
|
||||
crate::app::AppPolicy {
|
||||
persist_plugin_registry: true,
|
||||
..crate::app::AppPolicy::TEST
|
||||
},
|
||||
None,
|
||||
rx,
|
||||
crate::api::EventHub::default(),
|
||||
)
|
||||
.expect("corrupt registry must not prevent server startup");
|
||||
assert!(app.state.installed_plugins.is_empty());
|
||||
drop(app);
|
||||
std::fs::remove_file(registry).unwrap();
|
||||
|
||||
let broken =
|
||||
crate::plugin_paths::create_managed_installation("example.broken").unwrap();
|
||||
std::fs::create_dir(broken.join(LEASE_FILE)).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user