Remove packaged RW directories before copying unpacked directories 77/224077/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 6 Feb 2020 05:59:33 +0000 (14:59 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 6 Feb 2020 10:47:04 +0000 (19:47 +0900)
Change-Id: I7afa8a50a72ebbd755518a90bedd8f352dbcd122
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/backup/step_copy_backup.cc
src/common/step/backup/step_copy_backup.h
src/common/step/filesystem/step_copy.cc
src/common/step/filesystem/step_copy.h

index 10f8465..c5a8352 100644 (file)
@@ -15,9 +15,9 @@
 #include <string>
 
 #include "common/paths.h"
+#include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
 #include "common/utils/user_util.h"
-#include "common/shared_dirs.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
@@ -27,6 +27,9 @@ namespace {
 
 const char kExternalMemoryMountPoint[] = ".mmc";
 const char kSharedResPath[] = "shared/res";
+const char kCachePath[] = "cache";
+const char kDataPath[] = "data";
+const char kSharedDataPath[] = "shared/data";
 
 bool CheckFreeSpace(const bf::path& backup_path, const bf::path& shared_path) {
   int64_t shared_size = ci::GetDirectorySize(shared_path);
@@ -226,7 +229,18 @@ void StepCopyBackup::RemoveContent() {
   }
 }
 
+void StepCopyBackup::RemoveRWDirectories() {
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kCachePath))
+    LOG(ERROR) << "Failed to remove packaged cache directory";
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kDataPath))
+    LOG(ERROR) << "Failed to remove packaged data directory";
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kSharedDataPath))
+    LOG(ERROR) << "Failed to remove packaged shared/data directory";
+}
+
 bool StepCopyBackup::NewContent() {
+  RemoveRWDirectories();
+
   bs::error_code error;
   bf::create_directories(install_path_.parent_path(), error);
   if (error) {
index 6a637ee..1a3a806 100644 (file)
@@ -60,6 +60,7 @@ class StepCopyBackup : public Step {
   bool RollbackApplicationDirectory();
   bool MoveMountPointContent(const boost::filesystem::path& from,
                    const boost::filesystem::path& to);
+  void RemoveRWDirectories();
 
   boost::filesystem::path install_path_;
   boost::filesystem::path backup_path_;
index f86f746..2bca440 100644 (file)
@@ -9,13 +9,23 @@
 #include <cstring>
 #include <string>
 
+#include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
 
-namespace common_installer {
-namespace filesystem {
-
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
+namespace ci = common_installer;
+
+namespace {
+
+const char kCachePath[] = "cache";
+const char kDataPath[] = "data";
+const char kSharedDataPath[] = "shared/data";
+
+}  // namespace
+
+namespace common_installer {
+namespace filesystem {
 
 Step::Status StepCopy::precheck() {
   if (context_->root_application_path.get().empty()) {
@@ -53,6 +63,16 @@ Step::Status StepCopy::precheck() {
   return Step::Status::OK;
 }
 
+void StepCopy::RemoveRWDirectories() {
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kCachePath))
+    LOG(ERROR) << "Failed to remove packaged cache directory";
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kDataPath))
+    LOG(ERROR) << "Failed to remove packaged data directory";
+  if (!RemoveAll(context_->unpacked_dir_path.get() / kSharedDataPath))
+    LOG(ERROR) << "Failed to remove packaged shared/data directory";
+}
+
+
 Step::Status StepCopy::process() {
   bf::path install_path;
   if (context_->storage.get() == Storage::EXTENDED) {
@@ -62,6 +82,8 @@ Step::Status StepCopy::process() {
     install_path = context_->GetPkgPath();
   }
 
+  RemoveRWDirectories();
+
   bs::error_code error;
   bf::create_directories(install_path.parent_path(), error);
   if (error) {
index d4887d2..0fd4630 100644 (file)
@@ -47,6 +47,9 @@ class StepCopy : public Step {
    */
   Status precheck() override;
 
+ private:
+  void RemoveRWDirectories();
+
   STEP_NAME(Copy)
 };