Check space before backup while installation 63/174263/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 29 Mar 2018 10:46:44 +0000 (19:46 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 29 Mar 2018 23:09:21 +0000 (08:09 +0900)
- Backup algorithm changed from move to copy for several directories
  for access permission.
- Due to change above, extra storage is needed to back it up but
  calculating it was missing.

Change-Id: Ia935d1ba460f19ddc0dfb69e13015f78d00fec32
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/step/backup/step_copy_backup.cc
src/common/step/filesystem/step_unzip.cc
src/common/utils/file_util.cc
src/common/utils/file_util.h

index a78021b..53eab0a 100644 (file)
@@ -11,6 +11,7 @@
 #include <boost/system/error_code.hpp>
 
 #include <cassert>
+#include <cstdint>
 #include <string>
 
 #include "common/paths.h"
@@ -54,6 +55,14 @@ bool BackupContents(const bf::path& src, const bf::path& backup_path) {
   return true;
 }
 
+bool CheckFreeSpace(const bf::path& backup_path, const bf::path& shared_path) {
+  int64_t shared_size = ci::GetDirectorySize(shared_path);
+  if (!ci::CheckFreeSpaceAtPath(shared_size, backup_path))
+    return false;
+
+  return true;
+}
+
 }  // namespace
 
 namespace common_installer {
@@ -75,6 +84,11 @@ Step::Status StepCopyBackup::precheck() {
   install_path_ = context_->pkg_path.get();
   backup_path_ = GetBackupPathForPackagePath(context_->pkg_path.get());
 
+  if (!CheckFreeSpace(backup_path_, install_path_ / "shared")) {
+    LOG(ERROR) << "not enough space for backup";
+    return Step::Status::OUT_OF_SPACE;
+  }
+
   return Status::OK;
 }
 
index e6be344..45361ca 100644 (file)
@@ -26,26 +26,6 @@ namespace {
 
 const char kPackageUnpackDirPath[] = UNPACKDIR;
 
-bool CheckFreeSpaceAtPath(int64_t required_size,
-    const boost::filesystem::path& target_location) {
-  bs::error_code error;
-  boost::filesystem::path root = target_location;
-  while (!bf::exists(root) && root != root.root_path()) {
-    root = root.parent_path();
-  }
-  if (!bf::exists(root)) {
-    LOG(ERROR) << "No mount point for path: " << target_location;
-    return false;
-  }
-  bf::space_info space_info = bf::space(root, error);
-  if (error) {
-    LOG(ERROR) << "Failed to get space_info: " << error.message();
-    return false;
-  }
-
-  return (space_info.free >= static_cast<uint64_t>(required_size));
-}
-
 }  // namespace
 
 namespace common_installer {
index 93a6374..08b175d 100644 (file)
@@ -430,6 +430,26 @@ int64_t GetDirectorySize(const boost::filesystem::path& path) {
   return size;
 }
 
+bool CheckFreeSpaceAtPath(int64_t required_size,
+    const boost::filesystem::path& target_location) {
+  bs::error_code error;
+  boost::filesystem::path root = target_location;
+  while (!bf::exists(root) && root != root.root_path())
+    root = root.parent_path();
+
+  if (!bf::exists(root)) {
+    LOG(ERROR) << "No mount point for path: " << target_location;
+    return false;
+  }
+  bf::space_info space_info = bf::space(root, error);
+  if (error) {
+    LOG(ERROR) << "Failed to get space_info: " << error.message();
+    return false;
+  }
+
+  return (space_info.free >= static_cast<uint64_t>(required_size));
+}
+
 boost::filesystem::path GenerateTmpDir(const bf::path &app_path) {
   boost::filesystem::path install_tmp_dir;
   boost::filesystem::path tmp_dir(app_path);
index b2ed7a7..7cafda6 100644 (file)
@@ -58,6 +58,9 @@ int64_t GetUnpackedPackageSize(const boost::filesystem::path& path);
 
 int64_t GetDirectorySize(const boost::filesystem::path& path);
 
+bool CheckFreeSpaceAtPath(int64_t required_size,
+    const boost::filesystem::path& target_location);
+
 boost::filesystem::path GenerateTmpDir(const boost::filesystem::path& app_path);
 
 boost::filesystem::path GenerateTemporaryPath(