Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / recovery_file.cc
index ace2414..d7999ab 100644 (file)
@@ -4,26 +4,21 @@
 
 #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 {
 
@@ -65,8 +60,8 @@ namespace common_installer {
 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;
   }
@@ -79,8 +74,8 @@ std::unique_ptr<RecoveryFile> RecoveryFile::CreateRecoveryFile(
 }
 
 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;
   }
@@ -93,7 +88,7 @@ std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFile(
   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";
@@ -128,7 +123,7 @@ bool RecoveryFile::is_detached() const {
 }
 
 void RecoveryFile::set_unpacked_dir(
-    boost::filesystem::path unpacked_dir) {
+    std::filesystem::path unpacked_dir) {
   unpacked_dir_ = std::move(unpacked_dir);
 }
 
@@ -149,7 +144,7 @@ void RecoveryFile::set_security_operation_done(bool security_operation_done) {
   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_;
 }
 
@@ -236,9 +231,9 @@ bool RecoveryFile::ReadFileContent() {
 }
 
 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;
@@ -246,7 +241,7 @@ bool RecoveryFile::WriteAndCommitFileContent() {
     }
   }
 
-  bi::stream<bi::file_descriptor_sink> ofs(path_);
+  std::ofstream ofs(path_);
   if (!ofs) {
     LOG(ERROR) << "Cannot write recovery file";
     return false;
@@ -290,8 +285,8 @@ bool RecoveryFile::WriteAndCommitFileContent() {
   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;
@@ -299,4 +294,3 @@ bool RecoveryFile::WriteAndCommitFileContent() {
 
 }  // namespace recovery
 }  // namespace common_installer
-