summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlho Kim <ilho159.kim@samsung.com>2024-10-15 16:04:41 +0900
committerIlho Kim <ilho159.kim@samsung.com>2024-10-16 11:02:30 +0900
commita12887c45b026ebf11ab934f087767d8f27ad9cc (patch)
tree905c80bf1610ae9e333461dfc5e309ed1bdaad65
parent5e01cd814550d4514ea0a07e544b32dcd7b3b827 (diff)
downloadapp-installers-a12887c45b026ebf11ab934f087767d8f27ad9cc.tar.gz
app-installers-a12887c45b026ebf11ab934f087767d8f27ad9cc.tar.bz2
app-installers-a12887c45b026ebf11ab934f087767d8f27ad9cc.zip
Change the location of the recovery file
A recovery file is created in the application root directory of the user A folder with package id,a recovery file may exist together in this path This can be confusing to find a recovery file if the package id is similar to the recovery file format Change-Id: I1f4cfd3157d1abaef89e2436b5edb67557271b89 Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
-rw-r--r--src/common/global_recovery_file.cc16
-rw-r--r--src/common/recovery_file.cc7
-rw-r--r--src/common/step/recovery/step_create_recovery_file.cc3
-rw-r--r--src/common/utils/request.cc4
-rw-r--r--src/common/utils/request.h4
-rw-r--r--src/pkg_recovery/pkg_recovery.cc11
6 files changed, 38 insertions, 7 deletions
diff --git a/src/common/global_recovery_file.cc b/src/common/global_recovery_file.cc
index f4f57fd2..af61b278 100644
--- a/src/common/global_recovery_file.cc
+++ b/src/common/global_recovery_file.cc
@@ -54,8 +54,16 @@ GlobalRecoveryFile::~GlobalRecoveryFile() {
bool GlobalRecoveryFile::Init() {
- std::filesystem::path root_path = ci::GetRootAppPath(
- pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid());
+ std::filesystem::path root_path = ci::GetRecoveryFilePath(
+ ci::GetRootAppPath(pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid()));
+ if (!fs::exists(root_path)) {
+ std::error_code error;
+ fs::create_directories(root_path, error);
+ if (error) {
+ LOG(ERROR) << "Cannot create directory " << error.message();
+ return false;
+ }
+ }
recovery_filepath_ = GenerateRecoveryFilePath(root_path, kGlobalTypeName);
if (recovery_filepath_.empty())
return false;
@@ -65,8 +73,8 @@ bool GlobalRecoveryFile::Init() {
std::string GlobalRecoveryFile::AddPathWithType(
const std::string& pkg_type) {
- std::filesystem::path root_path = ci::GetRootAppPath(
- pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid());
+ std::filesystem::path root_path = ci::GetRecoveryFilePath(
+ ci::GetRootAppPath(pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid()));
fs::path recovery_filepath = GenerateRecoveryFilePath(root_path, pkg_type);
if (!AppendString(recovery_filepath.string()))
return {};
diff --git a/src/common/recovery_file.cc b/src/common/recovery_file.cc
index d7999ab4..cb8b82a4 100644
--- a/src/common/recovery_file.cc
+++ b/src/common/recovery_file.cc
@@ -64,6 +64,13 @@ std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFile(
if (fs::exists(path)) {
LOG(ERROR) << "Recovery file already exists!";
return nullptr;
+ } else if (!fs::exists(path.parent_path())) {
+ std::error_code error;
+ fs::create_directories(path.parent_path(), error);
+ if (error) {
+ LOG(ERROR) << "Cannot create directory " << error.message();
+ return nullptr;
+ }
}
std::unique_ptr<RecoveryFile> file(new RecoveryFile(path, type, false));
if (file->is_detached()) {
diff --git a/src/common/step/recovery/step_create_recovery_file.cc b/src/common/step/recovery/step_create_recovery_file.cc
index f2e139ce..43f308af 100644
--- a/src/common/step/recovery/step_create_recovery_file.cc
+++ b/src/common/step/recovery/step_create_recovery_file.cc
@@ -32,7 +32,8 @@ Step::Status StepCreateRecoveryFile::process() {
if (recovery_filename.empty()) {
std::string file_format = context_->pkg_type.get() + "-recovery";
recovery_filename = GenerateTemporaryPath(
- context_->root_application_path.get() / file_format);
+ GetRecoveryFilePath(
+ context_->root_application_path.get()) / file_format);
}
auto recovery_file =
diff --git a/src/common/utils/request.cc b/src/common/utils/request.cc
index 85ff2a7a..4d0d07e2 100644
--- a/src/common/utils/request.cc
+++ b/src/common/utils/request.cc
@@ -78,4 +78,8 @@ const char* GetExtendedRootAppPath(uid_t uid) {
}
}
+fs::path GetRecoveryFilePath(const std::filesystem::path& root_path) {
+ return root_path / ".recovery";
+}
+
} // namespace common_installer
diff --git a/src/common/utils/request.h b/src/common/utils/request.h
index 09d5a130..bb2c0c7c 100644
--- a/src/common/utils/request.h
+++ b/src/common/utils/request.h
@@ -5,6 +5,7 @@
#ifndef COMMON_UTILS_REQUEST_H_
#define COMMON_UTILS_REQUEST_H_
+#include <filesystem>
#include <string>
namespace common_installer {
@@ -70,6 +71,9 @@ const char* GetRootAppPath(bool is_readonly, uid_t uid);
*/
const char* GetExtendedRootAppPath(uid_t uid);
+std::filesystem::path GetRecoveryFilePath(
+ const std::filesystem::path& root_path);
+
} // namespace common_installer
#endif // COMMON_UTILS_REQUEST_H_
diff --git a/src/pkg_recovery/pkg_recovery.cc b/src/pkg_recovery/pkg_recovery.cc
index fb186275..5fce8e7f 100644
--- a/src/pkg_recovery/pkg_recovery.cc
+++ b/src/pkg_recovery/pkg_recovery.cc
@@ -128,7 +128,10 @@ void PkgRecoveryService::Run() {
}
void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
- const fs::path recovery_dir = ci::GetRootAppPath(false, uid);
+ const fs::path recovery_dir =
+ ci::GetRecoveryFilePath(ci::GetRootAppPath(false, uid));
+ if (!fs::exists(recovery_dir))
+ return;
try {
for (fs::directory_iterator iter(recovery_dir);
iter != fs::directory_iterator();
@@ -151,8 +154,12 @@ void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
std::vector<RecoverEntry> PkgRecoveryService::SearchRecoveryFiles(uid_t uid) {
std::vector<RecoverEntry> list;
- const fs::path recovery_dir = ci::GetRootAppPath(false, uid);
+ const fs::path recovery_dir =
+ ci::GetRecoveryFilePath(ci::GetRootAppPath(false, uid));
LOG(INFO) << "RootAppPath: " << recovery_dir;
+ if (!fs::exists(recovery_dir))
+ return list;
+
for (fs::directory_iterator iter(recovery_dir);
iter != fs::directory_iterator();
++iter) {