Add checking routine after getting pkg type 90/241190/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 18 Aug 2020 10:55:47 +0000 (19:55 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 25 Aug 2020 02:18:38 +0000 (11:18 +0900)
Installer may failed to get pkg type with given input

Change-Id: I38921f4ebf3e19eac4ff7679e26a4cef644762b2
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/unified/unified_installer_factory.cc

index 176f83bb261ec6591dfa3f605e4ad436e599f3a2..239fc9aa9c24cfa245d9553ccf6b6aed03dccaa3 100644 (file)
@@ -30,9 +30,16 @@ std::map<const char*, const char*> kTypeMap = {
   {"tizen-manifest.xml", "tpk"},
 };
 
+std::string ValidatePkgType(const std::string& type) {
+  if (type == "tpk" || type == "wgt")
+    return type;
+  else
+    return {};
+}
+
 std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
   ci::PkgQueryInterface query(pkgid, uid);
-  return query.Type();
+  return ValidatePkgType(query.Type());
 }
 
 std::string GetPkgTypeFromPath(const std::string& path) {
@@ -52,7 +59,8 @@ std::string GetPkgTypeFromPath(const std::string& path) {
   if (type.empty())
     LOG(ERROR) << "Cannot get pkg type";
   unzClose(uf);
-  return type;
+
+  return ValidatePkgType(type);
 }
 
 std::string GetPkgTypeFromFilename(const boost::filesystem::path& name) {
@@ -61,7 +69,7 @@ std::string GetPkgTypeFromFilename(const boost::filesystem::path& name) {
   std::stringstream ss(filename);
 
   std::getline(ss, token, '-');
-  return token;
+  return ValidatePkgType(token);
 }
 
 }  // namespace
@@ -92,8 +100,11 @@ std::unique_ptr<AppInstaller> UnifiedInstallerFactory::CreateInstaller(
   std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx),
       pkgmgr->GetUid());
 
-  if (type.empty())
+  if (type.empty()) {
+    LOG(ERROR) << "Failed to identify package type, input : "
+               << pkgmgr->GetRequestInfo(idx);
     return {};
+  }
 
   std::unique_ptr<ci::AppInstaller> installer;
   if (type == "tpk") {