From a80b142f8bf653180633daba4d435152de295fe3 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 17 Feb 2020 14:41:37 +0900 Subject: [PATCH] Fix StepUnzip to checking free space before creating tmp directory Change-Id: I4024cf9f7d74d5d1f281de54c91ed79f25f33288 Signed-off-by: Sangyoon Jang --- src/common/step/filesystem/step_unzip.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/common/step/filesystem/step_unzip.cc b/src/common/step/filesystem/step_unzip.cc index 45361ca..a0bc3b4 100644 --- a/src/common/step/filesystem/step_unzip.cc +++ b/src/common/step/filesystem/step_unzip.cc @@ -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); -- 2.7.4