activation: Replace exists() with is_symlink()/is_directory()
When the symlink is pointing to a directory that doesn't exist,
the exists() check returns false even though the symlink exists,
causing the symlink to not be removed so a failure occurs when
changing the symlink to point to a new version.
Check instead via is_symlink which doesn't care if the target
that the symlink is pointing at exists or not.
This could happen when the user deletes the image that the
symlink is pointing at before activating a new image.
Also use is_directory() to check for directory existance.
Change-Id: Id4548c2f3292b5460317951334d9151e2c4fbab7
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index 98df52b..eeefbef 100755
--- a/activation.cpp
+++ b/activation.cpp
@@ -52,24 +52,24 @@
// existence of those directories to validate the service file was
// successful, also for the existence of the RO directory where the
// image is supposed to reside.
- if ((fs::exists(PNOR_PRSV)) &&
- (fs::exists(PNOR_RW_PREFIX + versionId)) &&
- (fs::exists(PNOR_RO_PREFIX + versionId)))
+ if ((fs::is_directory(PNOR_PRSV)) &&
+ (fs::is_directory(PNOR_RW_PREFIX + versionId)) &&
+ (fs::is_directory(PNOR_RO_PREFIX + versionId)))
{
- if (!fs::exists(PNOR_ACTIVE_PATH))
+ if (!fs::is_directory(PNOR_ACTIVE_PATH))
{
fs::create_directories(PNOR_ACTIVE_PATH);
}
// If the RW or RO active links exist, remove them and create new
// ones pointing to the active version.
- if (fs::exists(PNOR_RO_ACTIVE_PATH))
+ if (fs::is_symlink(PNOR_RO_ACTIVE_PATH))
{
fs::remove(PNOR_RO_ACTIVE_PATH);
}
fs::create_directory_symlink(PNOR_RO_PREFIX + versionId,
PNOR_RO_ACTIVE_PATH);
- if (fs::exists(PNOR_RW_ACTIVE_PATH))
+ if (fs::is_symlink(PNOR_RW_ACTIVE_PATH))
{
fs::remove(PNOR_RW_ACTIVE_PATH);
}
@@ -78,7 +78,7 @@
// There is only one preserved directory as it is not tied to a
// version, so just create the link if it doesn't exist already.
- if (!fs::exists(PNOR_PRSV_ACTIVE_PATH))
+ if (!fs::is_symlink(PNOR_PRSV_ACTIVE_PATH))
{
fs::create_directory_symlink(PNOR_PRSV, PNOR_PRSV_ACTIVE_PATH);
}