From: Tomasz Iwanek Date: Thu, 2 Apr 2015 09:28:50 +0000 (+0200) Subject: [Gardening] Several fixes X-Git-Tag: accepted/tizen/common/20150430.095307~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F38770%2F1;p=platform%2Fcore%2Fappfw%2Fapp-installers.git [Gardening] Several fixes - Byte size literals, - use nullptr, - some TODOs solved or removed, Change-Id: I50517cf4c54b1d3134a7d6bbe98b556e15432f23 --- diff --git a/src/common/pkgmgr_signal.h b/src/common/pkgmgr_signal.h index de3fb0d..1907918 100644 --- a/src/common/pkgmgr_signal.h +++ b/src/common/pkgmgr_signal.h @@ -11,6 +11,7 @@ #include #include "common/step/step.h" +#include "utils/macros.h" namespace common_installer { @@ -51,9 +52,7 @@ class PkgmgrSignal { pkgmgr_installer* pi_; static State state_; - // TODO(t.iwanek): use DISALLOW_COPY_AND_ASSIGN - PkgmgrSignal(const PkgmgrSignal&) = delete; - PkgmgrSignal& operator=(const PkgmgrSignal&) = delete; + DISALLOW_COPY_AND_ASSIGN(PkgmgrSignal); }; } // namespace common_installer diff --git a/src/common/step/step.h b/src/common/step/step.h index 7388dea..c39c725 100644 --- a/src/common/step/step.h +++ b/src/common/step/step.h @@ -4,7 +4,7 @@ // found in the LICENSE file. /* - A step is made of 3 functions (that can be defined or NULL) + A step is made of 3 functions (that can be defined or null) and one data pointer. The functions are: diff --git a/src/common/step/step_generate_xml.cc b/src/common/step/step_generate_xml.cc index 8029c28..6afc35f 100644 --- a/src/common/step/step_generate_xml.cc +++ b/src/common/step/step_generate_xml.cc @@ -136,7 +136,7 @@ Step::Status StepGenerateXml::process() { return Step::Status::ERROR; } - xmlTextWriterStartDocument(writer, NULL, NULL, NULL); + xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr); xmlTextWriterSetIndent(writer, 1); diff --git a/src/common/step/step_unzip.cc b/src/common/step/step_unzip.cc index 2de4e0b..f85063e 100644 --- a/src/common/step/step_unzip.cc +++ b/src/common/step/step_unzip.cc @@ -21,10 +21,15 @@ #include #include +#include "utils/byte_size_literals.h" #include "utils/file_util.h" -#define ZIPBUFSIZE 8192 -#define ZIPMAXPATH 256 +namespace { + +unsigned kZipBufSize = 8_kB; +unsigned kZipMaxPath = 256; + +} namespace bf = boost::filesystem; namespace bs = boost::system; @@ -55,7 +60,7 @@ int64_t GetUnpackedPackageSize(const bf::path& path) { unz_global_info info; unz_file_info64 raw_file_info; - char raw_file_name_in_zip[ZIPMAXPATH]; + char raw_file_name_in_zip[kZipMaxPath]; unzFile* zip_file = static_cast(unzOpen(path.string().c_str())); if (zip_file == nullptr) { @@ -71,7 +76,7 @@ int64_t GetUnpackedPackageSize(const bf::path& path) { for (uLong i = 0; i < info.number_entry; i++) { if (unzGetCurrentFileInfo64(zip_file, &raw_file_info, raw_file_name_in_zip, - sizeof(raw_file_name_in_zip), NULL, 0, NULL, 0) != UNZ_OK) { + sizeof(raw_file_name_in_zip), nullptr, 0, nullptr, 0) != UNZ_OK) { LOG(ERROR) << "Failed to read file info"; return -1; } @@ -136,14 +141,14 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src, } unz_global_info info; - char read_buffer[ZIPBUFSIZE]; + char read_buffer[kZipBufSize]; unz_file_info raw_file_info; - char raw_file_name_in_zip[ZIPMAXPATH]; + char raw_file_name_in_zip[kZipMaxPath]; current_path(tmp_dir); unzFile* zip_file = static_cast(unzOpen(src)); - if (zip_file == NULL) { + if (!zip_file) { LOG(ERROR) << "Failed to open the source dir: " << src; return Step::Status::ERROR; } @@ -156,7 +161,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src, for (uLong i = 0; i < info.number_entry; i++) { if (unzGetCurrentFileInfo(zip_file, &raw_file_info, raw_file_name_in_zip, - sizeof(raw_file_name_in_zip), NULL, 0, NULL, 0) != UNZ_OK) { + sizeof(raw_file_name_in_zip), nullptr, 0, nullptr, 0) != UNZ_OK) { LOG(ERROR) << "Failed to read file info"; unzClose(zip_file); return Step::Status::ERROR; @@ -190,7 +195,7 @@ Step::Status StepUnzip::ExtractToTmpDir(const char* src, int ret = UNZ_OK; do { - ret = unzReadCurrentFile(zip_file, read_buffer, ZIPBUFSIZE); + ret = unzReadCurrentFile(zip_file, read_buffer, kZipBufSize); if (ret < 0) { LOG(ERROR) << "Failed to read data: " << ret; unzCloseCurrentFile(zip_file); diff --git a/src/signature/signature_validator.cc b/src/signature/signature_validator.cc index f9070c0..f97c3ea 100644 --- a/src/signature/signature_validator.cc +++ b/src/signature/signature_validator.cc @@ -19,12 +19,13 @@ #include "signature/signature_data.h" #include "signature/signature_parser.h" #include "signature/signature_xmlsec_adaptor.h" +#include "utils/byte_size_literals.h" namespace bf = boost::filesystem; namespace { -const int kXMLLogSize = 1024; +const int kXMLLogSize = 1_kB; const char kAuthorSignatureName[] = "author-signature.xml"; const char kTokenRoleAuthorURI[] = diff --git a/src/tpk/step/step_parse.h b/src/tpk/step/step_parse.h index f7086cb..6dd259b 100644 --- a/src/tpk/step/step_parse.h +++ b/src/tpk/step/step_parse.h @@ -14,11 +14,10 @@ class StepParse : public common_installer::Step { using Step::Step; Status process() override; - Status clean() override { return Status::OK; }; - Status undo() override { return Status::OK; }; + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } Status precheck() override { return Status::OK; } - private: boost::filesystem::path* GetManifestFilePath( const boost::filesystem::path& dir); diff --git a/src/tpk/task.cc b/src/tpk/task.cc index 798d91f..15c907d 100644 --- a/src/tpk/task.cc +++ b/src/tpk/task.cc @@ -25,7 +25,9 @@ namespace ci = common_installer; namespace { - const char kPkgType[] = "tpk"; + +const char kPkgType[] = "tpk"; + } // namespace namespace tpk { diff --git a/src/tpk/task.h b/src/tpk/task.h index 80a5ef3..36db06c 100644 --- a/src/tpk/task.h +++ b/src/tpk/task.h @@ -15,7 +15,6 @@ class Task { bool Init(int argc, char** argv); bool Run(); - private: int Install(); int Uninstall(); @@ -23,4 +22,5 @@ class Task { }; // class Task } // namespace tpk + #endif // TPK_TASK_H_ diff --git a/src/utils/byte_size_literals.h b/src/utils/byte_size_literals.h new file mode 100644 index 0000000..ffb85be --- /dev/null +++ b/src/utils/byte_size_literals.h @@ -0,0 +1,21 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef UTILS_BYTE_SIZE_LITERALS_H_ +#define UTILS_BYTE_SIZE_LITERALS_H_ + +constexpr unsigned long long operator"" _kB(unsigned long long v) { // NOLINT + return v * (1 << 10); +} + +constexpr unsigned long long operator"" _MB(unsigned long long v) { // NOLINT + return v * (1 << 20); +} + +constexpr unsigned long long operator"" _GB(unsigned long long v) { // NOLINT + return v * (1 << 30); +} + +#endif // UTILS_BYTE_SIZE_LITERALS_H_ + diff --git a/src/utils/string_util.cc b/src/utils/string_util.cc index 5bf1ada..ddd9ad7 100644 --- a/src/utils/string_util.cc +++ b/src/utils/string_util.cc @@ -23,7 +23,7 @@ std::string DecodePercentEscapedCharacter(const std::string& path) { char str[3] = {"\0", }; str[0] = input[i + 1]; str[1] = input[i + 2]; - int result = strtol(str, NULL, 16); + int result = strtol(str, nullptr, 16); // RFC 1738 - octets 80 to FF are not allowed if (result >= 128) return std::string(); diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc index a33e03c..92d3890 100644 --- a/src/wgt/step/step_parse.cc +++ b/src/wgt/step/step_parse.cc @@ -211,8 +211,8 @@ common_installer::Step::Status StepParse::process() { new WidgetHandler }; - std::unique_ptr registry; - registry.reset(new parser::ManifestHandlerRegistry(handlers)); + std::unique_ptr registry( + new parser::ManifestHandlerRegistry(handlers)); parser_.reset(new parser::ManifestParser(std::move(registry))); if (!parser_->ParseManifest(config_)) { diff --git a/src/xml_parser/xml_parser.cc b/src/xml_parser/xml_parser.cc index 24fe3e9..ab1dfe6 100644 --- a/src/xml_parser/xml_parser.cc +++ b/src/xml_parser/xml_parser.cc @@ -156,7 +156,7 @@ XmlTree* XmlParser::ParseAndGetNewTree(const char* xmlFilePath) { LIBXML_TEST_VERSION XmlTree* t = nullptr; - xmlDocPtr doc = xmlReadFile(xmlFilePath, NULL, 0); + xmlDocPtr doc = xmlReadFile(xmlFilePath, nullptr, 0); if (doc) { t = new XmlTree(doc); } else { diff --git a/src/xml_parser/xml_parser.h b/src/xml_parser/xml_parser.h index a009632..7bb0d67 100644 --- a/src/xml_parser/xml_parser.h +++ b/src/xml_parser/xml_parser.h @@ -54,8 +54,6 @@ class XmlParser { XmlParser(); ~XmlParser(); XmlTree* ParseAndGetNewTree(const char* xmlFilePath = ""); - - private: }; } // namespace xml_parser