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;
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 {};
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()) {
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 =
}
}
+fs::path GetRecoveryFilePath(const std::filesystem::path& root_path) {
+ return root_path / ".recovery";
+}
+
} // namespace common_installer
#ifndef COMMON_UTILS_REQUEST_H_
#define COMMON_UTILS_REQUEST_H_
+#include <filesystem>
#include <string>
namespace common_installer {
*/
const char* GetExtendedRootAppPath(uid_t uid);
+std::filesystem::path GetRecoveryFilePath(
+ const std::filesystem::path& root_path);
+
} // namespace common_installer
#endif // COMMON_UTILS_REQUEST_H_
}
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();
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) {