Fix StepUnzip to checking free space before creating tmp directory 54/225054/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 17 Feb 2020 05:41:37 +0000 (14:41 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 25 Feb 2020 00:47:00 +0000 (00:47 +0000)
Change-Id: I4024cf9f7d74d5d1f281de54c91ed79f25f33288
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/filesystem/step_unzip.cc

index 45361ca..a0bc3b4 100644 (file)
@@ -60,24 +60,12 @@ Step::Status StepUnzip::precheck() {
 Step::Status StepUnzip::process() {
   bf::path tmp_dir = GenerateTmpDir(kPackageUnpackDirPath);
 
-  // write unpacked directory for recovery file
-  if (context_->recovery_info.get().recovery_file) {
-    context_->recovery_info.get().recovery_file->set_unpacked_dir(tmp_dir);
-    context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
-  }
-
-  if (!CreateDir(tmp_dir)) {
-    LOG(ERROR) << "Failed to create temp directory: " << tmp_dir;
-    return Step::Status::APP_DIR_ERROR;
-  }
-
   int64_t required_size =
       GetUnpackedPackageSize(context_->file_path.get());
 
   if (required_size == -1) {
     LOG(ERROR) << "Couldn't get uncompressed size for package: "
                << context_->file_path.get();
-    RemoveAll(tmp_dir);
     return Step::Status::APP_DIR_ERROR;
   }
 
@@ -85,17 +73,27 @@ Step::Status StepUnzip::process() {
 
   if (!CheckFreeSpaceAtPath(required_size, tmp_dir)) {
     LOG(ERROR) << "There is not enough space to unpack application files";
-    RemoveAll(tmp_dir);
     return Step::Status::OUT_OF_SPACE;
   }
 
   if (!CheckFreeSpaceAtPath(required_size,
       bf::path(context_->root_application_path.get()))) {
     LOG(ERROR) << "There is not enough space to install application files";
-    RemoveAll(tmp_dir);
     return Step::Status::OUT_OF_SPACE;
   }
 
+  // write unpacked directory for recovery file
+  if (context_->recovery_info.get().recovery_file) {
+    context_->recovery_info.get().recovery_file->set_unpacked_dir(tmp_dir);
+    context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
+  }
+
+  if (!CreateDir(tmp_dir)) {
+    LOG(ERROR) << "Failed to create temp directory: " << tmp_dir;
+    return Step::Status::APP_DIR_ERROR;
+  }
+
+
   if (!ExtractToTmpDir(context_->file_path.get().string().c_str(), tmp_dir)) {
     LOG(ERROR) << "Failed to process unpack step";
     RemoveAll(tmp_dir);