From b3dcf07f58b7b30536396bad9d221c2fe41879d7 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 13 Sep 2023 09:55:44 -0700 Subject: [PATCH] Check for file existence before attempting to open it (#626) * Check for file existence before attempting to open it * Fixup --- src/action/base/create_file.rs | 4 ++++ src/action/base/create_or_insert_into_file.rs | 5 +++++ src/planner/linux.rs | 4 ++-- src/planner/ostree.rs | 2 +- src/planner/steam_deck.rs | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/action/base/create_file.rs b/src/action/base/create_file.rs index 31cf16d..18667ff 100644 --- a/src/action/base/create_file.rs +++ b/src/action/base/create_file.rs @@ -266,6 +266,10 @@ impl Action for CreateFile { buf: _, force: _, } = self; + // The user already deleted it + if !path.exists() { + return Ok(()); + } remove_file(&path) .await diff --git a/src/action/base/create_or_insert_into_file.rs b/src/action/base/create_or_insert_into_file.rs index 3deedd2..cf0e237 100644 --- a/src/action/base/create_or_insert_into_file.rs +++ b/src/action/base/create_or_insert_into_file.rs @@ -339,6 +339,11 @@ impl Action for CreateOrInsertIntoFile { buf, position: _, } = self; + // The user already deleted it + if !path.exists() { + return Ok(()); + } + let mut file = OpenOptions::new() .create(false) .write(true) diff --git a/src/planner/linux.rs b/src/planner/linux.rs index 835ae58..81ab4b7 100644 --- a/src/planner/linux.rs +++ b/src/planner/linux.rs @@ -104,8 +104,8 @@ impl Planner for Linux { let Self { settings, init } = self; let mut map = HashMap::default(); - map.extend(settings.settings()?.into_iter()); - map.extend(init.settings()?.into_iter()); + map.extend(settings.settings()?); + map.extend(init.settings()?); Ok(map) } diff --git a/src/planner/ostree.rs b/src/planner/ostree.rs index 472e762..554ebbb 100644 --- a/src/planner/ostree.rs +++ b/src/planner/ostree.rs @@ -234,7 +234,7 @@ impl Planner for Ostree { } = self; let mut map = HashMap::default(); - map.extend(settings.settings()?.into_iter()); + map.extend(settings.settings()?); map.insert( "persistence".to_string(), serde_json::to_value(persistence)?, diff --git a/src/planner/steam_deck.rs b/src/planner/steam_deck.rs index 9646831..a4ac1ff 100644 --- a/src/planner/steam_deck.rs +++ b/src/planner/steam_deck.rs @@ -360,7 +360,7 @@ impl Planner for SteamDeck { } = self; let mut map = HashMap::default(); - map.extend(settings.settings()?.into_iter()); + map.extend(settings.settings()?); map.insert( "persistence".to_string(), serde_json::to_value(persistence)?,