Fix removing packaged rw directories 51/243251/6
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 4 Sep 2020 07:56:49 +0000 (16:56 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 14 Sep 2020 06:41:25 +0000 (06:41 +0000)
Remove shared/trusted directory when update case.
Make util function to remove rw directories.

Change-Id: Ide197cbcd97a4e6faf7faf1941880a50abf711fb
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/shared_dirs.cc
src/common/shared_dirs.h
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
src/common/step/filesystem/step_create_storage_directories.cc
src/common/step/mount/step_mount_install.cc
src/common/step/mount/step_mount_update.cc

index 447ce05..4f3d25b 100644 (file)
@@ -619,21 +619,17 @@ bool CreateStorageDirectories(const boost::filesystem::path& path,
   return true;
 }
 
-bool DeleteStorageDirectories(const boost::filesystem::path& path,
-                              const std::string& pkgid) {
-  std::vector<const char*> dirs;
-  dirs.assign(kEntries.begin() + 1, kEntries.end());
-  dirs.push_back(kSharedTrustedDir);
-  dirs.push_back(kSharedCacheDir);
-  for (auto& entry : dirs) {
-    bf::path subpath = path / pkgid / entry;
-    if (!ci::RemoveAll(subpath))
-      return false;
-  }
-  if (!DeleteSharedDataDirectories(path, pkgid))
-    return false;
-
-  return true;
+void RemoveRWDirectories(const boost::filesystem::path& root) {
+  if (!RemoveAll(root / kCache))
+    LOG(ERROR) << "Failed to remove packaged cache directory";
+  if (!RemoveAll(root / kData))
+    LOG(ERROR) << "Failed to remove packaged data directory";
+  if (!RemoveAll(root / kSharedCacheDir))
+    LOG(ERROR) << "Failed to remove packaged shared/cache directory";
+  if (!RemoveAll(root / kSharedDataDir))
+    LOG(ERROR) << "Failed to remove packaged shared/data directory";
+  if (!RemoveAll(root / kSharedTrustedDir))
+    LOG(ERROR) << "Failed to remove packaged shared/trusted directory";
 }
 
 bool DeleteSharedDirectories(const bf::path& path,
index 3d1f606..939aa4a 100644 (file)
@@ -108,15 +108,12 @@ bool DeletePerUserStorageDirectories(const std::string& pkgid,
                                      bool keep_rwdata = false);
 
 /**
- * \brief Deletes storage directories in path
+ * \brief Deletes RW directories in path, this should be invoked after
+ *        unzipping package for remove rw directories
  *
- * \param path base path, which contains storage directories
- * \param pkgid package id
- *
- * \return true if succeed, false otherwise
+ * \param path base path, which contains rw directories
  */
-bool DeleteStorageDirectories(const boost::filesystem::path& path,
-                              const std::string& pkgid);
+void RemoveRWDirectories(const boost::filesystem::path& root);
 
 /**
  * \brief Deletes shared directories in path
index e2b27a6..7f83059 100644 (file)
@@ -27,9 +27,6 @@ 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);
@@ -221,17 +218,8 @@ 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();
+  ci::RemoveRWDirectories(context_->unpacked_dir_path.get());
 
   bs::error_code error;
   bf::create_directories(install_path_.parent_path(), error);
index 1a3a806..6a637ee 100644 (file)
@@ -60,7 +60,6 @@ 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 2bca440..d8b47b6 100644 (file)
@@ -16,14 +16,6 @@ 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 {
 
@@ -63,16 +55,6 @@ 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) {
@@ -82,7 +64,7 @@ Step::Status StepCopy::process() {
     install_path = context_->GetPkgPath();
   }
 
-  RemoveRWDirectories();
+  ci::RemoveRWDirectories(context_->unpacked_dir_path.get());
 
   bs::error_code error;
   bf::create_directories(install_path.parent_path(), error);
index 0fd4630..214cfce 100644 (file)
@@ -48,8 +48,6 @@ class StepCopy : public Step {
   Status precheck() override;
 
  private:
-  void RemoveRWDirectories();
-
   STEP_NAME(Copy)
 };
 
index 929be93..93d430f 100644 (file)
@@ -30,17 +30,6 @@ bool StepCreateStorageDirectories::CreatePerUserStorageDirs(
   LOG(INFO) << "Creating per-user directories for package: "
             << context_->pkgid.get();
 
-  RequestType req_type = context_->request_type.get();
-  if (req_type != RequestType::ManifestPartialInstall &&
-      req_type != RequestType::ManifestDirectInstall) {
-    // remove packaged RW diriectories
-    if (!DeleteStorageDirectories(context_->root_application_path.get(),
-                                  context_->pkgid.get())) {
-      LOG(ERROR) << "Failed to remove storage directories";
-      return false;
-    }
-  }
-
   bool is_readonly = context_->is_readonly_package.get();
   if (!CreatePerUserStorageDirectories(context_->pkgid.get(), trusted,
         shareddata, is_readonly, additional_shared_dirs_)) {
index 1aa4e48..a10d291 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <string>
 
+#include "common/shared_dirs.h"
 #include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
@@ -17,6 +18,7 @@
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
+namespace ci = common_installer;
 
 namespace common_installer {
 namespace mount {
@@ -43,6 +45,7 @@ Step::Status StepMountInstall::process() {
   if (!CopyFile(context_->file_path.get(), zip_destination_path)) {
     return Status::APP_DIR_ERROR;
   }
+  ci::RemoveRWDirectories(zip_destination_path);
   context_->manifest_data.get()->zip_mount_file =
       strdup(zip_destination_path.c_str());
 
index 449414a..b21d4dd 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <string>
 
+#include "common/shared_dirs.h"
 #include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
@@ -17,6 +18,7 @@
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
+namespace ci = common_installer;
 
 namespace common_installer {
 namespace mount {
@@ -40,6 +42,7 @@ Step::Status StepMountUpdate::process() {
   if (!CopyFile(context_->file_path.get(), zip_destination_path)) {
     return Status::APP_DIR_ERROR;
   }
+  ci::RemoveRWDirectories(zip_destination_path);
   context_->manifest_data.get()->zip_mount_file =
       strdup(zip_destination_path.c_str());