From: Sangyoon Jang Date: Fri, 4 Sep 2020 07:56:49 +0000 (+0900) Subject: Fix removing packaged rw directories X-Git-Tag: accepted/tizen/6.0/unified/20201030.121514~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ad44c7c8ce1430ab9b90ffc96b8e950230f1596;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Fix removing packaged rw directories Remove shared/trusted directory when update case. Make util function to remove rw directories. Change-Id: Ide197cbcd97a4e6faf7faf1941880a50abf711fb Signed-off-by: Sangyoon Jang --- diff --git a/src/common/shared_dirs.cc b/src/common/shared_dirs.cc index 447ce05..4f3d25b 100644 --- a/src/common/shared_dirs.cc +++ b/src/common/shared_dirs.cc @@ -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 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, diff --git a/src/common/shared_dirs.h b/src/common/shared_dirs.h index 3d1f606..939aa4a 100644 --- a/src/common/shared_dirs.h +++ b/src/common/shared_dirs.h @@ -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 diff --git a/src/common/step/backup/step_copy_backup.cc b/src/common/step/backup/step_copy_backup.cc index e2b27a6..7f83059 100644 --- a/src/common/step/backup/step_copy_backup.cc +++ b/src/common/step/backup/step_copy_backup.cc @@ -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); diff --git a/src/common/step/backup/step_copy_backup.h b/src/common/step/backup/step_copy_backup.h index 1a3a806..6a637ee 100644 --- a/src/common/step/backup/step_copy_backup.h +++ b/src/common/step/backup/step_copy_backup.h @@ -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_; diff --git a/src/common/step/filesystem/step_copy.cc b/src/common/step/filesystem/step_copy.cc index 2bca440..d8b47b6 100644 --- a/src/common/step/filesystem/step_copy.cc +++ b/src/common/step/filesystem/step_copy.cc @@ -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); diff --git a/src/common/step/filesystem/step_copy.h b/src/common/step/filesystem/step_copy.h index 0fd4630..214cfce 100644 --- a/src/common/step/filesystem/step_copy.h +++ b/src/common/step/filesystem/step_copy.h @@ -48,8 +48,6 @@ class StepCopy : public Step { Status precheck() override; private: - void RemoveRWDirectories(); - STEP_NAME(Copy) }; diff --git a/src/common/step/filesystem/step_create_storage_directories.cc b/src/common/step/filesystem/step_create_storage_directories.cc index 929be93..93d430f 100644 --- a/src/common/step/filesystem/step_create_storage_directories.cc +++ b/src/common/step/filesystem/step_create_storage_directories.cc @@ -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_)) { diff --git a/src/common/step/mount/step_mount_install.cc b/src/common/step/mount/step_mount_install.cc index 1aa4e48..a10d291 100644 --- a/src/common/step/mount/step_mount_install.cc +++ b/src/common/step/mount/step_mount_install.cc @@ -9,6 +9,7 @@ #include +#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()); diff --git a/src/common/step/mount/step_mount_update.cc b/src/common/step/mount/step_mount_update.cc index 449414a..b21d4dd 100644 --- a/src/common/step/mount/step_mount_update.cc +++ b/src/common/step/mount/step_mount_update.cc @@ -9,6 +9,7 @@ #include +#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());