namespace {
const char kExternalMemoryMountPoint[] = ".mmc";
+const char kSharedResPath[] = "shared/res";
+
+bool CheckFreeSpace(const bf::path& backup_path, const bf::path& shared_path) {
+ int64_t shared_size = ci::GetDirectorySize(shared_path);
+ if (!ci::CheckFreeSpaceAtPath(shared_size, backup_path))
+ return false;
-bool RemoveContents(const bf::path& path) {
- for (bf::directory_iterator iter(path);
- iter != bf::directory_iterator(); ++iter) {
- if (!ci::RemoveAll(iter->path()))
- return false;
- }
return true;
}
-bool BackupContents(const bf::path& src, const bf::path& backup_path) {
- if (!ci::CopyDir(src, backup_path,
- ci::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS, false))
+bool CreateSharedRes(const bf::path& src, const bf::path& dst) {
+ bs::error_code error;
+ bf::create_directories(dst / kSharedResPath, error);
+ if (error) {
+ LOG(ERROR) << "Cannot create package directory";
return false;
- for (bf::directory_iterator iter(src);
- iter != bf::directory_iterator(); ++iter) {
- if (iter->path().filename() == "res") {
- if (!RemoveContents(iter->path()))
- return false;
- continue;
- }
-
- if (!ci::RemoveAll(iter->path()))
- return false;
}
- return true;
-}
-
-bool CheckFreeSpace(const bf::path& backup_path, const bf::path& shared_path) {
- int64_t shared_size = ci::GetDirectorySize(shared_path);
- if (!ci::CheckFreeSpaceAtPath(shared_size, backup_path))
+ if (!ci::CopyOwnershipAndPermissions(src / "shared", dst / "shared") ||
+ !ci::CopyOwnershipAndPermissions(src / kSharedResPath,
+ dst / kSharedResPath))
return false;
return true;
}
}
- if (iter->path() == context_->GetPkgPath() / "shared") {
- if (!BackupContents(iter->path(), backup_path_ / "shared"))
- return false;
- continue;
- }
if (bf::is_directory(iter->path())) {
if (!MoveDir(iter->path(), backup_path_ / iter->path().filename())) {
LOG(ERROR) << "Fail to backup package directory of: " << iter->path();
}
}
}
+
+ if (bf::exists(backup_path_ / kSharedResPath) &&
+ bf::exists(context_->unpacked_dir_path.get() / kSharedResPath))
+ if (!CreateSharedRes(backup_path_, context_->GetPkgPath()))
+ return false;
+
recovery::RecoveryFile* recovery_file =
context_->recovery_info.get().recovery_file.get();
recovery_file->set_backup_done(true);