Don't try to delete target if it doesn't exist
Deleting a non-existent directory fails.
Bug: 211050731
Bug: 210460516
Test: compos_cmd async-odrefresh, with & without target dir
Test: atest ComposHostTestCases
Change-Id: I15989ab6f65edc1029970dbc80128c3e78288747
diff --git a/compos/composd/src/odrefresh_task.rs b/compos/composd/src/odrefresh_task.rs
index bcdf2f4..b7de479 100644
--- a/compos/composd/src/odrefresh_task.rs
+++ b/compos/composd/src/odrefresh_task.rs
@@ -22,7 +22,7 @@
ICompilationTask::ICompilationTask, ICompilationTaskCallback::ICompilationTaskCallback,
};
use android_system_composd::binder::{Interface, Result as BinderResult, Strong};
-use anyhow::{anyhow, bail, Context, Result};
+use anyhow::{bail, Context, Result};
use compos_aidl_interface::aidl::com::android::compos::ICompOsService::ICompOsService;
use compos_common::odrefresh::ExitCode;
use log::{error, warn};
@@ -113,7 +113,10 @@
// (and can't see the existing one, since authfs doesn't show it existing files in an output
// directory).
let target_path = output_root.join(target_dir_name);
- remove_dir_all(&target_path).with_context(|| anyhow!("Deleting {}", target_path.display()))?;
+ if target_path.exists() {
+ remove_dir_all(&target_path)
+ .with_context(|| format!("Failed to delete {}", target_path.display()))?;
+ }
let staging_dir = open_dir(composd_native::palette_create_odrefresh_staging_directory()?)?;
let system_dir = open_dir(Path::new("/system"))?;