From: Junghyun Yeon Date: Thu, 28 Nov 2019 00:18:02 +0000 (+0900) Subject: Fix StepEncryptResources X-Git-Tag: accepted/tizen/5.5/unified/20200105.221118~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af489d9d75a35ab926b56d436df01d05a3c4aee2;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Fix StepEncryptResources - Fix typo. - Use summarized namespace for readability. - Remove some 1 line if statement braces. Change-Id: Id42e04fca3516ce19c783d4cb6ef7af9a74d4891 Signed-off-by: Junghyun Yeon --- diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 2f00998..4d18750 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -92,7 +92,7 @@ #include "hybrid/step/configuration/step_merge_tpk_privileges.h" #include "hybrid/step/configuration/step_set_mainapp.h" #include "hybrid/step/configuration/step_stash_tpk_config.h" -#include "hybrid/step/encryption/step_encrypt_resources.h" +#include "hybrid/step/encryption/step_encrypt_hybrid_resources.h" #include "hybrid/step/pkgmgr/step_merge_xml.h" #include "wgt/step/configuration/step_parse.h" #include "wgt/step/configuration/step_set_old_signature_files_location.h" @@ -137,7 +137,7 @@ void HybridInstaller::InstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(false); @@ -189,7 +189,7 @@ void HybridInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); @@ -287,7 +287,7 @@ void HybridInstaller::DeltaSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -365,7 +365,7 @@ void HybridInstaller::MountInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -417,7 +417,7 @@ void HybridInstaller::MountUpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); @@ -640,7 +640,7 @@ void HybridInstaller::ReadonlyUpdateInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, diff --git a/src/hybrid/step/encryption/step_encrypt_resources.cc b/src/hybrid/step/encryption/step_encrypt_hybrid_resources.cc similarity index 73% rename from src/hybrid/step/encryption/step_encrypt_resources.cc rename to src/hybrid/step/encryption/step_encrypt_hybrid_resources.cc index 2265a35..b56bc30 100644 --- a/src/hybrid/step/encryption/step_encrypt_resources.cc +++ b/src/hybrid/step/encryption/step_encrypt_hybrid_resources.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by an apache-2.0 license that can be // found in the LICENSE file. -#include "hybrid/step/encryption/step_encrypt_resources.h" +#include "hybrid/step/encryption/step_encrypt_hybrid_resources.h" namespace hybrid { namespace encryption { -void StepEncryptResources::SetEncryptionRoot() { +void StepEncryptHybridResources::SetEncryptionRoot() { input_ = context_->unpacked_dir_path.get() / "res/wgt"; } diff --git a/src/hybrid/step/encryption/step_encrypt_resources.h b/src/hybrid/step/encryption/step_encrypt_hybrid_resources.h similarity index 66% rename from src/hybrid/step/encryption/step_encrypt_resources.h rename to src/hybrid/step/encryption/step_encrypt_hybrid_resources.h index 88b0f5b..2360651 100644 --- a/src/hybrid/step/encryption/step_encrypt_resources.h +++ b/src/hybrid/step/encryption/step_encrypt_hybrid_resources.h @@ -2,8 +2,8 @@ // Use of this source code is governed by an apache-2.0 license that can be // found in the LICENSE file. -#ifndef HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_RESOURCES_H_ -#define HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_RESOURCES_H_ +#ifndef HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_HYBRID_RESOURCES_H_ +#define HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_HYBRID_RESOURCES_H_ #include @@ -17,17 +17,18 @@ namespace encryption { * * This is variant for hybrid package */ -class StepEncryptResources : public wgt::encryption::StepEncryptResources { +class StepEncryptHybridResources : + public wgt::encryption::StepEncryptResources { public: using wgt::encryption::StepEncryptResources::StepEncryptResources; private: void SetEncryptionRoot() override; - STEP_NAME(EncryptResources) + STEP_NAME(EncryptHybridResources) }; } // namespace encryption } // namespace hybrid -#endif // HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_RESOURCES_H_ +#endif // HYBRID_STEP_ENCRYPTION_STEP_ENCRYPT_HYBRID_RESOURCES_H_ diff --git a/src/wgt/step/encryption/step_encrypt_resources.cc b/src/wgt/step/encryption/step_encrypt_resources.cc index dc4b6ec..dffaa89 100644 --- a/src/wgt/step/encryption/step_encrypt_resources.cc +++ b/src/wgt/step/encryption/step_encrypt_resources.cc @@ -22,12 +22,16 @@ #include #include +namespace bf = boost::filesystem; +namespace bs = boost::system; +namespace ci = common_installer; + namespace { const std::size_t kEncryptionChunkMaxSize = 8_kB; // bytes const std::set encryptSet { ".html", ".htm", ".css", ".js"}; -FILE* OpenFile(const std::string& path, const std::string& mode) { +FILE* OpenFile(const bf::path& path, const std::string& mode) { FILE* result = nullptr; do { @@ -77,14 +81,11 @@ void WriteBytes(unsigned char* buffer, std::size_t count, FILE* stream) { namespace wgt { namespace encryption { -namespace bf = boost::filesystem; -namespace bs = boost::system; - -common_installer::Step::Status StepEncryptResources::precheck() { +ci::Step::Status StepEncryptResources::precheck() { backend_data_ = static_cast(context_->backend_data.get()); if (!backend_data_) { LOG(ERROR) << "no backend data"; - return common_installer::Step::Status::ERROR; + return ci::Step::Status::ERROR; } SetEncryptionRoot(); @@ -98,22 +99,22 @@ common_installer::Step::Status StepEncryptResources::precheck() { return Step::Status::INVALID_VALUE; } - return common_installer::Step::Status::OK; + return ci::Step::Status::OK; } -common_installer::Step::Status StepEncryptResources::process() { +ci::Step::Status StepEncryptResources::process() { if (!backend_data_->settings.get().encryption_enabled()) { LOG(DEBUG) << "no encryption"; - return common_installer::Step::Status::OK; + return ci::Step::Status::OK; } LOG(DEBUG) << "Encrypting"; if (!Encrypt(input_)) { LOG(ERROR) << "Error during encryption"; - return common_installer::Step::Status::ERROR; + return ci::Step::Status::ERROR; } - return common_installer::Step::Status::OK; + return ci::Step::Status::OK; } bool StepEncryptResources::Encrypt(const bf::path &src) { @@ -124,21 +125,25 @@ bool StepEncryptResources::Encrypt(const bf::path &src) { for (bf::directory_iterator file(src); file != bf::directory_iterator(); ++file) { - bs::error_code error_code; + bs::error_code error; bf::path current(file->path()); - bool is_dir = bf::is_directory(current, error_code); - if (error_code) + bool is_dir = bf::is_directory(current, error); + if (error) { + LOG(ERROR) << "Failed to check directory status: " << error.message(); return false; + } if (is_dir) { if (!Encrypt(current)) return false; continue; } - bool is_sym = bf::is_symlink(symlink_status(current, error_code)); - if (error_code) + bool is_sym = bf::is_symlink(symlink_status(current, error)); + if (error) { + LOG(ERROR) << "Failed to check symlink status: " << error.message(); return false; + } if (is_sym) continue; @@ -153,51 +158,49 @@ bool StepEncryptResources::Encrypt(const bf::path &src) { } bool StepEncryptResources::EncryptFile(const bf::path &src) { - bf::path encFile(src.string() + ".enc"); struct stat info; memset(&info, 0, sizeof(info)); - if (stat(src.string().c_str(), &info) != 0) { - LOG(ERROR) << "Could not access file " << src.string(); + if (stat(src.c_str(), &info) != 0) { + LOG(ERROR) << "Could not access file " << src; return false; } const std::size_t fileSize = info.st_size; - if (0 == fileSize) { - LOG(ERROR) << src.string().c_str() << " size is 0, so encryption is skiped"; + if (!fileSize) { + LOG(ERROR) << src << " size is 0, so encryption will be skipped"; return true; } - FILE *input = OpenFile(src.string().c_str(), "rb"); - if (input == nullptr) { - LOG(ERROR) << "Cannot open file for encryption: " << src.string(); + FILE *input = OpenFile(src, "rb"); + if (!input) { + LOG(ERROR) << "Cannot open file for encryption: " << src; return false; } - FILE *output = OpenFile(encFile.string().c_str(), "wb"); - if (output == nullptr) { - LOG(ERROR) << "Cannot create encrypted file: " << encFile.string(); + bf::path encFile(src.string() + ".enc"); + FILE *output = OpenFile(encFile, "wb"); + if (!output) { + LOG(ERROR) << "Cannot create encrypted file: " << encFile; fclose(input); return false; } - std::size_t chunkSize = (fileSize > kEncryptionChunkMaxSize - ? kEncryptionChunkMaxSize : fileSize); + std::size_t chunkSize = (fileSize > kEncryptionChunkMaxSize ? + kEncryptionChunkMaxSize : fileSize); std::unique_ptr inChunk(new unsigned char[chunkSize]); std::size_t bytesRead = 0; do { bytesRead = ReadBytes(inChunk.get(), chunkSize, input); - if (0 != bytesRead) { + if (!bytesRead) { unsigned char* encrypted_data = nullptr; size_t encrypted_size = 0; // TODO(p.sikorski) check if it is Preloaded int ret; - if (context_->request_mode.get() - == common_installer::RequestMode::GLOBAL) { + if (context_->request_mode.get() == ci::RequestMode::GLOBAL) { ret = wae_encrypt_global_web_application( context_->pkgid.get().c_str(), - context_->is_readonly_package.get() ? - true : false, + context_->is_readonly_package.get() ? true : false, inChunk.get(), (size_t)bytesRead, &encrypted_data, @@ -263,14 +266,12 @@ bool StepEncryptResources::EncryptFile(const bf::path &src) { fclose(input); LOG(DEBUG) << "File encrypted successfully"; - if (0 != unlink(src.string().c_str())) { + if (!unlink(src.c_str())) return false; - } LOG(DEBUG) << "Rename encrypted file"; - if (0 != std::rename(encFile.c_str(), src.string().c_str())) { + if (!std::rename(encFile.c_str(), src.c_str())) return false; - } return true; }