Improve code readability 64/258364/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 14 May 2021 05:18:27 +0000 (14:18 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 28 May 2021 07:26:41 +0000 (07:26 +0000)
- Extract constant string as constexpr variablres.
- Fix minor coding rule.

Change-Id: Ifd0a61d1f9ea0d27dae7a7d98b1e6c15ee7e1a7b
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkg_upgrade/src/backend_invoker.cc
src/pkg_upgrade/src/file_logbackend.cc
src/pkg_upgrade/src/pkg_finder.cc

index e5b6ea9..e15a847 100644 (file)
 #include "backend_invoker.hh"
 #include "logging.hh"
 
+namespace {
+
+constexpr char kManifestDirectInstallCmdStr[] = "-y";
+constexpr char kUninstallCmdStr[] = "-d";
+
+}  // namespace
+
 namespace common_fota {
 
 BackendInvoker::BackendInvoker(std::string pkgid, PkgType type, PkgLocation loc,
     PkgOperation op, bool removable) {
-  if (type == PkgType::WGT) {
+  if (type == PkgType::WGT)
     parameters_.push_back("/usr/bin/wgt-backend");
-  } else {
+  else
     parameters_.push_back("/usr/bin/tpk-backend");
-  }
 
   if (op == PkgOperation::INSTALL || op == PkgOperation::UPDATE) {
-    parameters_.push_back("-y");
+    parameters_.push_back(kManifestDirectInstallCmdStr);
     parameters_.push_back(std::move(pkgid));
     if (loc == PkgLocation::RO) {
       parameters_.push_back("--preload");
@@ -47,14 +53,14 @@ BackendInvoker::BackendInvoker(std::string pkgid, PkgType type, PkgLocation loc,
     }
     parameters_.push_back("--skip-check-reference");
   } else if (op == PkgOperation::UNINSTALL) {
-    parameters_.push_back("-d");
+    parameters_.push_back(kUninstallCmdStr);
     parameters_.push_back(std::move(pkgid));
     if (loc == PkgLocation::RO)
       parameters_.push_back("--preload");
     parameters_.push_back("--force-remove");
     parameters_.push_back("--partial-rw");
   } else if (op == PkgOperation::UNINSTALL_KEEP_RW_DATA) {
-    parameters_.push_back("-d");
+    parameters_.push_back(kUninstallCmdStr);
     parameters_.push_back(std::move(pkgid));
     if (loc == PkgLocation::RO)
       parameters_.push_back("--preload");
@@ -67,9 +73,8 @@ int BackendInvoker::Run() const {
   const char* param[parameters_.size() + 1] = { nullptr, };
 
   int i = 0;
-  for (auto& str : parameters_) {
+  for (auto& str : parameters_)
     param[i++] = str.c_str();
-  }
 
   return XSystem(param);
 }
index 48c41dd..3303a67 100644 (file)
@@ -27,7 +27,6 @@
 #include "logging.hh"
 #include "file_logbackend.hh"
 
-
 namespace utils {
 
 FileLogBackend::FileLogBackend(std::string file_name, int rotation_size,
@@ -37,7 +36,6 @@ FileLogBackend::FileLogBackend(std::string file_name, int rotation_size,
           std::unique_ptr<std::ostringstream>(new std::ostringstream())) {
 }
 
-
 void FileLogBackend::WriteLog(LogLevel level, const std::string& /* tag */,
     const std::string& logstr) {
   if (level != LogLevel::LOG_DEBUG)
index 60cf2c0..f539faa 100644 (file)
@@ -42,6 +42,7 @@
 using std::string;
 
 namespace {
+
 constexpr char kOptZipFile[] = "/usr/system/RestoreDir/opt.zip";
 constexpr int kBufSize = 1024;
 constexpr char kSeperatorEnd = '"';
@@ -50,6 +51,10 @@ constexpr char kTokenTypeStr[] = "type=";
 constexpr char kTokenPkgidStr[] = "package=";
 constexpr char kTokenVersionStr[] = "version=";
 constexpr char kTokenRemoveStr[] = "removable=";
+
+constexpr char kDefaultVersionStr[] = "0.0.1";
+constexpr char kDefaultPkgTypeStr[] = "tpk";
+
 }  // namespace
 
 namespace common_fota {
@@ -196,11 +201,11 @@ int PkgFinder::FindPreloadPkgidFromXml(
     string version = FindInfoFromXml(buf, "version");
 
     if (version.empty())
-      version = "0.0.1";
+      version = kDefaultVersionStr;
 
     string type = FindInfoFromXml(buf, "type");
     if (type.empty())
-      type = "tpk";
+      type = kDefaultPkgTypeStr;
 
     new_pkgs_.emplace_back(pkgid, version, type, true);
   }