image_manager: Check if tmp dir exists before remove
There was an error seen where the version manager core dumped when
it tried to remove the temporary directory after a manifest failure:
phosphor-version-software-manager[1264]: Error No manifest file
phosphor-version-software-manager[1264]: terminate called after throwing an
instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
phosphor-version-software-manager[1264]: what(): filesystem error: cannot
remove all: No such file or directory [/tmp/images/imageKcwJFc]
To prevent the core dump, check that the directory exists before trying
to remove it. Create a journal error entry to aid debug since path should
exist.
Change-Id: Ifb47f9a44aa8835c8b7416c7e1a0e67c664d6160
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/image_manager.cpp b/image_manager.cpp
index 4a27260..69df9dd 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -38,7 +38,16 @@
RemovablePath(const fs::path& path) : path(path) {}
~RemovablePath()
{
- fs::remove_all(path);
+ if (fs::exists(path))
+ {
+ fs::remove_all(path);
+ }
+ else
+ {
+ // Path should exist
+ log<level::ERR>("Error removable path does not exist",
+ entry("PATH=%s", path.c_str()));
+ }
}
};