Change tpk archive info implementation 27/256527/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 6 Apr 2021 08:35:29 +0000 (17:35 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 3 Jun 2021 02:58:41 +0000 (02:58 +0000)
- Implement ExtractPackageArchive().
- Use RemoveTmpDir() to remove temporary directory.

Related changes:
[app-installers] : https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-installers/+/256526

Change-Id: Idc594544019b0e3d9d5e73012cfd92b2935d31d3
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/lib/tpk_archive_info.cc
src/lib/tpk_archive_info.h

index 0ad312847c36b5a54d9e5578ac451e4cfb7bd6cf..34e317eae3138aa58d23cdfc712a18ee6ab3a1cd 100644 (file)
@@ -37,17 +37,18 @@ const char kVconfLanguageKey[] = VCONFKEY_LANGSET;
 const char kManifestFileName[] = "tizen-manifest.xml";
 const char kSharedResDir[] = "shared/res";
 
-bool ExtractPackageArchive(const std::string& archive_path,
-    const std::string& file, const bf::path& tmp_dir) {
-  if (!ci::ExtractToTmpDir(archive_path.c_str(), tmp_dir, file.c_str())) {
+}  // namespace
+
+bool TpkArchiveInfo::ExtractPackageArchive(const std::string& archive_path,
+    const std::string& file, const std::string& tmp_dir) {
+  if (!ci::ExtractToTmpDir(archive_path.c_str(), bf::path(tmp_dir),
+          file.c_str())) {
     LOG(ERROR) << "Failed to extract";
     return false;
   }
   return true;
 }
 
-}  // namespace
-
 bool TpkArchiveInfo::GetPackageInfo(const tpk::parse::TPKConfigParser& parser) {
   auto pkg_info =
       std::static_pointer_cast<const tpk::parse::PackageInfo>(
@@ -238,7 +239,7 @@ bool TpkArchiveInfo::LoadArchiveInfo() {
   if (!ci::CreateDir(tmp_dir))
     return false;
   LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir;
-  if (!ExtractPackageArchive(path_, kManifestFileName, tmp_dir))
+  if (!ExtractPackageArchive(path_, kManifestFileName, tmp_dir.string()))
     return false;
 
   tpk::parse::TPKConfigParser parser;
@@ -275,18 +276,18 @@ bool TpkArchiveInfo::LoadArchiveInfo() {
   free(locale);
   if (!icon_.empty()) {
     bf::path icon_path = bf::path(kSharedResDir) / icon_;
-    if (!ExtractPackageArchive(path_, icon_path.string(), tmp_dir)) {
-      ci::RemoveAll(tmp_dir);
+    if (!ExtractPackageArchive(path_, icon_path.string(), tmp_dir.string())) {
+      RemoveTmpDir(tmp_dir.string());
       return false;
     }
     if (!ReadIcon(icon_path, tmp_dir)) {
       LOG(WARNING) << "Failed to get icon info";
-      ci::RemoveAll(tmp_dir);
+      RemoveTmpDir(tmp_dir.string());
       return false;
     }
   }
 
-  ci::RemoveAll(tmp_dir);
+  RemoveTmpDir(tmp_dir.string());
 
   return true;
 }
index ebcfa19787e3e4b46d5bae421ebd6e44b0efeb9d..e54b8bac05d223fc9407b59fd769cefb20096b6f 100644 (file)
@@ -20,6 +20,8 @@ class TpkArchiveInfo : public common_installer::ArchiveInfo {
   explicit TpkArchiveInfo(std::string path)
       : common_installer::ArchiveInfo(path) { }
   bool LoadArchiveInfo() override;
+  bool ExtractPackageArchive(const std::string& archive_path,
+      const std::string& file, const std::string& tmp_dir) override;
 
  protected:
   bool GetPackageInfo(const tpk::parse::TPKConfigParser& parser);