}
RecoveryFile::RecoveryFile(const bf::path& path, RequestType type, bool load)
- : type_(type), path_(path), backup_done_(false) {
+ : type_(type), path_(path), backup_done_(false), cleanup_(false) {
if (load) {
if (!ReadFileContent()) {
path_.clear();
backup_done_ = backup_done;
}
+void RecoveryFile::set_cleanup(bool cleanup) {
+ cleanup_ = cleanup;
+}
+
const boost::filesystem::path& RecoveryFile::unpacked_dir() const {
return unpacked_dir_;
}
return backup_done_;
}
+bool RecoveryFile::cleanup() const {
+ return cleanup_;
+}
+
bool RecoveryFile::ReadFileContent() {
FILE* handle = fopen(path_.c_str(), "r");
if (!handle) {
backup_done_ = true;
else
backup_done_ = false;
+ if (!fgets(data.data(), data.size(), handle)) {
+ fclose(handle);
+ return true;
+ }
+ std::string cleanup_flag = TruncateNewLine(data.data());
+ if (cleanup_flag == "cleanup")
+ cleanup_ = true;
+ else
+ cleanup_ = false;
fclose(handle);
return true;
}
fputs("\n", handle);
fputs(backup_done_ ? "true" : "false", handle);
fputs("\n", handle);
+ fputs(cleanup_ ? "cleanup" : "rollback", handle);
+ fputs("\n", handle);
fclose(handle);
sync();
return true;
void set_backup_done(bool backup_done);
/**
+ * setter for cleanup flag
+ *
+ * \param cleanup boolean value of cleanup
+ */
+ void set_cleanup(bool cleanup);
+
+ /**
* getter for unpacked dir
*
* \return current unpacked_dir
bool backup_done() const;
/**
+ * getter for cleanup flag
+ *
+ * \return true if cleanup flag has set
+ */
+ bool cleanup() const;
+
+ /**
* Transaction of current RecoveryFile content into recovery file
*
* \return true if success
boost::filesystem::path path_;
bool backup_done_;
+ bool cleanup_;
};
} // namespace recovery
}
Step::Status StepCopyBackup::clean() {
+ recovery::RecoveryFile* recovery_file =
+ context_->recovery_info.get().recovery_file.get();
+ recovery_file->set_cleanup(true);
+ recovery_file->WriteAndCommitFileContent();
+
if (!CleanBackupDirectory()) {
LOG(DEBUG) << "Cannot remove backup directory";
return Status::APP_DIR_ERROR;
#include "common/paths.h"
#include "common/recovery_file.h"
+#include "common/request.h"
#include "common/utils/file_util.h"
namespace bf = boost::filesystem;
return Status::OK;
}
+Step::Status StepRecoverFiles::Cleanup() {
+ recovery::RecoveryFile* recovery_file =
+ context_->recovery_info.get().recovery_file.get();
+ bf::path root_path(GetRootAppPath(
+ context_->is_readonly_package.get(), context_->uid.get()));
+ bf::path backup_path = GetBackupPathForPackagePath(
+ root_path / recovery_file->pkgid());
+ if (!bf::exists(backup_path))
+ return Status::OK;
+
+ if (!RemoveAll(backup_path)) {
+ LOG(ERROR) << "Failed to remove backup path";
+ return Status::RECOVERY_ERROR;
+ }
+
+ return Status::OK;
+}
+
} // namespace filesystem
} // namespace common_installer
Status RecoveryMountNew() override;
Status RecoveryMountUpdate() override;
Status RecoveryReadonlyUpdateInstall() override;
+ Status Cleanup() override;
STEP_NAME(RecoverFiles)
};
return RemoveFiles();
}
+Step::Status StepRemoveTemporaryDirectory::Cleanup() {
+ return RemoveFiles();
+}
+
Step::Status StepRemoveTemporaryDirectory::RemoveFiles() {
bf::path unpack_dir_path = context_->unpacked_dir_path.get();
bf::path patch_dir_path = unpack_dir_path;
Status RecoveryNew() override;
Status RecoveryUpdate() override;
+ Status Cleanup() override;
private:
/**
* @brief RemoveFiles
<< static_cast<int>(recovery_file->type()) << ")";
return Status::RECOVERY_ERROR;
}
+ if (recovery_file->cleanup())
+ LOG(INFO) << "Running cleanup operation";
context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
return Status::OK;
namespace recovery {
Step::Status StepRecovery::process() {
+ if (context_->recovery_info.get().recovery_file->cleanup())
+ return Cleanup();
+
switch (context_->recovery_info.get().recovery_file->type()) {
case RequestType::Install:
return RecoveryNew();
return RecoveryUpdate();
}
+Step::Status StepRecovery::Cleanup() {
+ return Status::OK;
+}
+
} // namespace recovery
} // namespace common_installer
virtual Status RecoveryMountNew();
virtual Status RecoveryMountUpdate();
virtual Status RecoveryReadonlyUpdateInstall();
+ virtual Status Cleanup();
};
} // namespace recovery