namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace {
+
+const char kExternalMemoryMountPoint[] = ".mmc";
+
+bool Move(const boost::filesystem::path& from,
+ const boost::filesystem::path& to,
+ common_installer::FSFlag flag = common_installer::FSFlag::FS_NONE) {
+ if (bf::is_directory(from)) {
+ if (!common_installer::MoveDir(from, to / from.filename(), flag)) {
+ LOG(ERROR) << "Failed to move directory: " << from;
+ return false;
+ }
+ } else {
+ if (!common_installer::MoveFile(from, to / from.filename())) {
+ LOG(ERROR) << "Fail to move file: " << from;
+ return false;
+ }
+ }
+
+ return true;
+}
+
+} // namespace
+
namespace common_installer {
namespace filesystem {
Step::Status StepRecoverFiles::RecoveryNew() {
- if (!RemoveAll(context_->GetPkgPath()))
+ if (!ClearPath(context_->GetPkgPath()))
return Status::RECOVERY_ERROR;
LOG(INFO) << "Package files recovery done";
if (bf::exists(backup_path)) {
// Remove pkgdir only if backup original contents is completely done.
if (backup_done) {
- if (!RemoveAll(context_->GetPkgPath())) {
- LOG(ERROR) << "Cannot restore widget files to its correct location";
- return Status::RECOVERY_ERROR;
+ for (bf::directory_iterator iter(context_->GetPkgPath());
+ iter != bf::directory_iterator(); ++iter) {
+ if (iter->path().filename() == kExternalMemoryMountPoint)
+ continue;
+
+ if (!ClearPath(iter->path())) {
+ LOG(ERROR) << "Cannot restore widget files to its correct location";
+ return Status::RECOVERY_ERROR;
+ }
}
// it may fail during recovery.
recovery_file->set_backup_done(false);
recovery_file->WriteAndCommitFileContent();
}
- (void) MoveDir(backup_path, context_->GetPkgPath(), FS_MERGE_OVERWRITE);
+
+ // create copy of old package content skipping the external memory mount point
+ for (bf::directory_iterator iter(backup_path);
+ iter != bf::directory_iterator(); ++iter) {
+ if (!Move(iter->path(), context_->GetPkgPath()))
+ return Status::RECOVERY_ERROR;
+ }
+
+ ClearPath(backup_path);
}
LOG(INFO) << "Package files recovery done";
return Status::OK;
bf::path zip_location = GetZipPackageLocation(
context_->GetPkgPath(), context_->pkgid.get());
Remove(zip_location);
- RemoveAll(context_->GetPkgPath());
+ ClearPath(context_->GetPkgPath());
LOG(INFO) << "Package files recovery done";
return Status::OK;
}
// still unpacked due to necessity.
bf::path backup_path = GetBackupPathForPackagePath(context_->GetPkgPath());
if (bf::exists(backup_path)) {
- if (!MoveDir(backup_path, context_->GetPkgPath(),
- FS_MERGE_OVERWRITE | FS_COMMIT_COPY_FILE)) {
- LOG(ERROR) << "Failed to recovery backup file "
- << "in recovery of mount update";
- return Status::APP_DIR_ERROR;
+ for (bf::directory_iterator iter(backup_path);
+ iter != bf::directory_iterator(); ++iter) {
+ ClearPath(context_->GetPkgPath() / iter->path().filename());
+ if (!Move(iter->path(), context_->GetPkgPath())) {
+ LOG(ERROR) << "Failed to recovery backup file(" << iter->path()
+ << ") in recovery of mount update";
+ return Status::RECOVERY_ERROR;
+ }
}
+ ClearPath(backup_path);
}
LOG(INFO) << "Package files recovery done";
bf::path pkg_path =
bf::path(GetRootAppPath(false, context_->uid.get())) /
context_->pkgid.get();
- if (!RemoveAll(pkg_path))
+ if (!ClearPath(pkg_path))
return Status::RECOVERY_ERROR;
LOG(INFO) << "Package files recovery done";
if (!bf::exists(backup_path))
return Status::OK;
- if (!RemoveAll(backup_path)) {
+ if (!ClearPath(backup_path)) {
LOG(ERROR) << "Failed to remove backup path";
return Status::RECOVERY_ERROR;
}
return Status::OK;
}
+bool StepRecoverFiles::ClearPath(const bf::path& path) {
+ return RemoveAll(path);
+}
+
} // namespace filesystem
} // namespace common_installer