#include "common/recovery_file.h"
-#include <boost/filesystem/operations.hpp>
-#include <boost/iostreams/stream.hpp>
-#include <boost/iostreams/device/file_descriptor.hpp>
-#include <boost/system/error_code.hpp>
-
#include <manifest_parser/utils/logging.h>
#include <array>
#include <cstring>
+#include <fstream>
#include <string>
+#include <system_error>
#include <map>
#include <utility>
#include "common/installer_context.h"
#include "common/utils/file_util.h"
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-namespace bi = boost::iostreams;
namespace ci = common_installer;
+namespace fs = std::filesystem;
namespace {
namespace recovery {
std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFile(
- const boost::filesystem::path& path, RequestType type) {
- if (bf::exists(path)) {
+ const std::filesystem::path& path, RequestType type) {
+ if (fs::exists(path)) {
LOG(ERROR) << "Recovery file already exists!";
return nullptr;
}
}
std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFile(
- const boost::filesystem::path& path) {
- if (!bf::exists(path)) {
+ const std::filesystem::path& path) {
+ if (!fs::exists(path)) {
LOG(ERROR) << "Cannot open recovery file";
return nullptr;
}
return file;
}
-RecoveryFile::RecoveryFile(const bf::path& path, RequestType type, bool load)
+RecoveryFile::RecoveryFile(const fs::path& path, RequestType type, bool load)
: type_(type), path_(path), backup_done_(false), cleanup_(false),
security_operation_done_(false) {
backup_path_ = path_.string() + ".bck";
}
void RecoveryFile::set_unpacked_dir(
- boost::filesystem::path unpacked_dir) {
+ std::filesystem::path unpacked_dir) {
unpacked_dir_ = std::move(unpacked_dir);
}
security_operation_done_ = security_operation_done;
}
-const boost::filesystem::path& RecoveryFile::unpacked_dir() const {
+const std::filesystem::path& RecoveryFile::unpacked_dir() const {
return unpacked_dir_;
}
}
bool RecoveryFile::WriteAndCommitFileContent() {
- if (bf::exists(path_)) {
- bs::error_code error;
- bf::rename(path_, backup_path_, error);
+ if (fs::exists(path_)) {
+ std::error_code error;
+ fs::rename(path_, backup_path_, error);
if (error) {
LOG(ERROR) << "Cannot backup recovery file:" << path_ <<
", error: " << error;
}
}
- bi::stream<bi::file_descriptor_sink> ofs(path_);
+ std::ofstream ofs(path_);
if (!ofs) {
LOG(ERROR) << "Cannot write recovery file";
return false;
ofs << (cleanup_ ? "cleanup" : "rollback") << std::endl;
ofs << (security_operation_done_ ? "true" : "false") << std::endl;
ofs.flush();
- ::fsync(ofs->handle());
ofs.close();
+ SyncFile(path_);
Remove(backup_path_);
return true;
} // namespace recovery
} // namespace common_installer
-