[Gardening] Several fixes 70/38770/1
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 2 Apr 2015 09:28:50 +0000 (11:28 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 28 Apr 2015 08:45:13 +0000 (10:45 +0200)
 - Byte size literals,
 - use nullptr,
 - some TODOs solved or removed,

Change-Id: I50517cf4c54b1d3134a7d6bbe98b556e15432f23

13 files changed:
src/common/pkgmgr_signal.h
src/common/step/step.h
src/common/step/step_generate_xml.cc
src/common/step/step_unzip.cc
src/signature/signature_validator.cc
src/tpk/step/step_parse.h
src/tpk/task.cc
src/tpk/task.h
src/utils/byte_size_literals.h [new file with mode: 0644]
src/utils/string_util.cc
src/wgt/step/step_parse.cc
src/xml_parser/xml_parser.cc
src/xml_parser/xml_parser.h

index de3fb0d..1907918 100644 (file)
@@ -11,6 +11,7 @@
 #include <string>
 
 #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
index 7388dea..c39c725 100644 (file)
@@ -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:
index 8029c28..6afc35f 100644 (file)
@@ -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);
 
index 2de4e0b..f85063e 100644 (file)
 #include <cstring>
 #include <string>
 
+#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<unzFile*>(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<unzFile*>(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);
index f9070c0..f97c3ea 100644 (file)
 #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[] =
index f7086cb..6dd259b 100644 (file)
@@ -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);
index 798d91f..15c907d 100644 (file)
@@ -25,7 +25,9 @@
 namespace ci = common_installer;
 
 namespace {
-  const char kPkgType[] = "tpk";
+
+const char kPkgType[] = "tpk";
+
 }  // namespace
 
 namespace tpk {
index 80a5ef3..36db06c 100644 (file)
@@ -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 (file)
index 0000000..ffb85be
--- /dev/null
@@ -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_
+
index 5bf1ada..ddd9ad7 100644 (file)
@@ -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();
index a33e03c..92d3890 100644 (file)
@@ -211,8 +211,8 @@ common_installer::Step::Status StepParse::process() {
     new WidgetHandler
   };
 
-  std::unique_ptr<parser::ManifestHandlerRegistry> registry;
-  registry.reset(new parser::ManifestHandlerRegistry(handlers));
+  std::unique_ptr<parser::ManifestHandlerRegistry> registry(
+      new parser::ManifestHandlerRegistry(handlers));
 
   parser_.reset(new parser::ManifestParser(std::move(registry)));
   if (!parser_->ParseManifest(config_)) {
index 24fe3e9..ab1dfe6 100644 (file)
@@ -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 {
index a009632..7bb0d67 100644 (file)
@@ -54,8 +54,6 @@ class XmlParser {
   XmlParser();
   ~XmlParser();
   XmlTree* ParseAndGetNewTree(const char* xmlFilePath = "");
-
- private:
 };
 
 }  // namespace xml_parser