Change the location of the recovery file 96/319096/4
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 15 Oct 2024 07:04:41 +0000 (16:04 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 16 Oct 2024 02:02:30 +0000 (11:02 +0900)
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>
src/common/global_recovery_file.cc
src/common/recovery_file.cc
src/common/step/recovery/step_create_recovery_file.cc
src/common/utils/request.cc
src/common/utils/request.h
src/pkg_recovery/pkg_recovery.cc

index f4f57fd2f3415fac1ff5ce65be14229f1ce66f28..af61b278a2993819c99b60cedc024a09b7cfe243 100644 (file)
@@ -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 {};
index d7999ab413dac9d0b57f9299374a2f3d387fe654..cb8b82a48f9e5a491349853092252bec904a00ff 100644 (file)
@@ -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()) {
index f2e139ce4128490052d76bda33ac472da2ed89fe..43f308af9edf1d7edf320d81920fe7d573a463ff 100644 (file)
@@ -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 =
index 85ff2a7aa4bdfa1a8383ba2c38607f0a98d26b0f..4d0d07e2f2d6c8e8570549947c481ccd8756dad8 100644 (file)
@@ -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
index 09d5a1306a4cafdad1685ba7cf57687190f33a95..bb2c0c7cd16fb1023df7d96d6eddfff49886d493 100644 (file)
@@ -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_
index fb18627504f7952dcfb3b0f465601c086cbdaf5b..5fce8e7fa4423cd402771256202107074c5cca6a 100644 (file)
@@ -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) {