Change wgt archive info implementation 28/256528/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 6 Apr 2021 08:37:14 +0000 (17:37 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 3 Jun 2021 02:58:57 +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: Ia314458b708b728a9542a4a18715e93616f5ce6c
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/lib/wgt_archive_info.cc
src/lib/wgt_archive_info.h

index 7552812..edc7d77 100644 (file)
@@ -32,17 +32,18 @@ const char kVconfLanguageKey[] = VCONFKEY_LANGSET;
 const char kConfigFileName[] = "config.xml";
 const char kHybridConfigFileName[] = "res/wgt/config.xml";
 
-bool ExtractPackageArchive(const std::string& file_path,
-    const std::string& file, const bf::path& tmp_dir) {
-  if (!ci::ExtractToTmpDir(file_path.c_str(), tmp_dir, file.c_str())) {
+}  // namespace
+
+bool WgtArchiveInfo::ExtractPackageArchive(const std::string& file_path,
+    const std::string& file, const std::string& tmp_dir) {
+  if (!ci::ExtractToTmpDir(file_path.c_str(),
+          bf::path(tmp_dir), file.c_str())) {
     LOG(ERROR) << "Failed to extract";
     return false;
   }
   return true;
 }
 
-}  // namespace
-
 bool WgtArchiveInfo::GetPackageInfo(
     const wgt::parse::WidgetConfigParser& parser) {
   auto widget_info =
@@ -202,12 +203,12 @@ bool WgtArchiveInfo::LoadArchiveInfo() {
     return false;
   LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir;
   bool is_hybrid = false;
-  if (!ExtractPackageArchive(path_, kHybridConfigFileName, tmp_dir))
+  if (!ExtractPackageArchive(path_, kHybridConfigFileName, tmp_dir.string()))
     return false;
   if (bf::exists(tmp_dir / kHybridConfigFileName)) {
     is_hybrid = true;
   } else {
-    if (!ExtractPackageArchive(path_, kConfigFileName, tmp_dir))
+    if (!ExtractPackageArchive(path_, kConfigFileName, tmp_dir.string()))
       return false;
   }
 
@@ -219,20 +220,20 @@ bool WgtArchiveInfo::LoadArchiveInfo() {
     manifest_path = tmp_dir / kConfigFileName;
   if (!parser.ParseManifest(manifest_path)) {
     LOG(ERROR) << "Failed to parse";
-    bf::remove_all(tmp_dir);
+    RemoveTmpDir(tmp_dir.string());
     return false;
   }
 
   if (!GetPackageInfo(parser)) {
     LOG(ERROR) << "Failed to get package info";
-    bf::remove_all(tmp_dir);
+    RemoveTmpDir(tmp_dir.string());
     return false;
   }
   if (!GetApplicationInfo(parser)) {
     if (!GetAddonInfo(parser)) {
       LOG(ERROR) << "Failed to get application info nor addon info. "
                  << "At least one of them must exist";
-      bf::remove_all(tmp_dir);
+      RemoveTmpDir(tmp_dir.string());
       return false;
     }
   }
@@ -247,13 +248,13 @@ bool WgtArchiveInfo::LoadArchiveInfo() {
       icon_path = "res/wgt/" + icon_;
     else
       icon_path = icon_;
-    if (!ExtractPackageArchive(path_, icon_path, tmp_dir)) {
-      bf::remove_all(tmp_dir);
+    if (!ExtractPackageArchive(path_, icon_path, tmp_dir.string())) {
+      RemoveTmpDir(tmp_dir.string());
       return false;
     }
     if (!ReadIcon(icon_path, tmp_dir)) {
       LOG(WARNING) << "Failed to get icon info";
-      bf::remove_all(tmp_dir);
+      RemoveTmpDir(tmp_dir.string());
       return false;
     }
   }
@@ -267,7 +268,8 @@ bool WgtArchiveInfo::LoadArchiveInfo() {
     LOG(WARNING) << "Failed to get description info";
 
   free(locale);
-  bf::remove_all(tmp_dir);
+  RemoveTmpDir(tmp_dir.string());
+
 
   return true;
 }
index debc32c..0f7a5a2 100644 (file)
@@ -20,6 +20,8 @@ class WgtArchiveInfo : public common_installer::ArchiveInfo {
   explicit WgtArchiveInfo(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;
 
  private:
   bool GetPackageInfo(const wgt::parse::WidgetConfigParser& parser);