Skip the security registration if it is unnecessary
[platform/core/appfw/app-installers.git] / src / common / recovery_file.cc
index cd1b632..ace2414 100644 (file)
@@ -94,7 +94,8 @@ std::unique_ptr<RecoveryFile> RecoveryFile::OpenRecoveryFile(
 }
 
 RecoveryFile::RecoveryFile(const bf::path& path, RequestType type, bool load)
-    : type_(type), path_(path), backup_done_(false), cleanup_(false) {
+    : type_(type), path_(path), backup_done_(false), cleanup_(false),
+      security_operation_done_(false) {
   backup_path_ = path_.string() + ".bck";
   if (load) {
     if (!ReadFileContent()) {
@@ -144,6 +145,10 @@ void RecoveryFile::set_cleanup(bool cleanup) {
   cleanup_ = cleanup;
 }
 
+void RecoveryFile::set_security_operation_done(bool security_operation_done) {
+  security_operation_done_ = security_operation_done;
+}
+
 const boost::filesystem::path& RecoveryFile::unpacked_dir() const {
   return unpacked_dir_;
 }
@@ -164,6 +169,10 @@ bool RecoveryFile::cleanup() const {
   return cleanup_;
 }
 
+bool RecoveryFile::security_operation_done() const {
+  return security_operation_done_;
+}
+
 bool RecoveryFile::ReadFileContent() {
   FILE* handle = fopen(path_.c_str(), "r");
   if (!handle) {
@@ -213,6 +222,15 @@ bool RecoveryFile::ReadFileContent() {
     cleanup_ = true;
   else
     cleanup_ = false;
+  if (!fgets(data.data(), data.size(), handle)) {
+    fclose(handle);
+    return true;
+  }
+  std::string security_operation_done_flag = TruncateNewLine(data.data());
+  if (security_operation_done_flag == "true")
+    security_operation_done_ = true;
+  else
+    security_operation_done_ = false;
   fclose(handle);
   return true;
 }
@@ -270,6 +288,7 @@ bool RecoveryFile::WriteAndCommitFileContent() {
   ofs << pkgid_ << std::endl;
   ofs << (backup_done_ ? "true" : "false") << std::endl;
   ofs << (cleanup_ ? "cleanup" : "rollback") << std::endl;
+  ofs << (security_operation_done_ ? "true" : "false") << std::endl;
   ofs.flush();
   ::fsync(ofs->handle());
   ofs.close();