Revert "Add send signal if there is not enough memory during web app installation"
[framework/web/wrt-installer.git] / src / jobs / widget_install / widget_unzip.cpp
index 28ef7b2..d41b890 100644 (file)
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
 #include <widget_install/job_widget_install.h>
-#include <dpl/log/log.h>
 #include <dpl/copy.h>
 #include <dpl/file_output.h>
+#include "dpl/utils/path.h"
 #include <dpl/abstract_waitable_input_adapter.h>
 #include <dpl/wrt-dao-ro/global_config.h>
-#include <task_commons.h>
 #include <sys/stat.h>
 #include <dlfcn.h>
+#include <installer_log.h>
 
 using namespace WrtDB;
 
@@ -90,10 +90,8 @@ void WidgetUnzip::ExtractFile(DPL::ZipInput::File *input,
 void WidgetUnzip::unzipProgress(const std::string &destination)
 {
     // Show file info
-    LogDebug("Unzipping: '" << m_zipIterator->name <<
-            "', Comment: '" << m_zipIterator->comment <<
-            "', Compressed size: " << m_zipIterator->compressedSize <<
-            ", Uncompressed size: " << m_zipIterator->uncompressedSize);
+    _D("Unzipping: '%s', Comment: '%s', Compressed size: %lld, Uncompressed size: %lld",
+            m_zipIterator->name.c_str(), m_zipIterator->comment.c_str(), m_zipIterator->compressedSize, m_zipIterator->uncompressedSize);
 
     // Normalize file paths
     // FIXME: Implement checking for invalid characters
@@ -105,25 +103,37 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
         // This is path
         std::string newPath = destination + "/" +
             fileName.substr(0, fileName.size() - 1);
-        LogPedantic("Path to extract: " << newPath);
+        _D("Path to extract: %s", newPath.c_str());
 
         // Create path in case of it is empty
-        createTempPath(newPath);
+        Try
+        {
+            DPL::Utils::MakeDir(DPL::Utils::Path(newPath));
+        }
+        Catch(DPL::Utils::Path::BaseException)
+        {
+            ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
+        }
     } else {
         // This is regular file
         std::string fileExtractPath = destination + "/" + fileName;
 
-        LogPedantic("File to extract: " << fileExtractPath);
+        _D("File to extract: %s", fileExtractPath.c_str());
 
         // Split into pat & file pair
         PathAndFilePair pathAndFile = SplitFileAndPath(fileExtractPath);
 
-        LogPedantic("Path and file: " <<
-                    pathAndFile.path <<
-                    " : " << pathAndFile.file);
+        _D("Path and file: %s : %s", pathAndFile.path.c_str(), pathAndFile.file.c_str());
 
         // First, ensure that path exists
-        createTempPath(pathAndFile.path);
+        Try
+        {
+            DPL::Utils::MakeDir(DPL::Utils::Path(pathAndFile.path));
+        }
+        Catch(DPL::Utils::Path::BaseException)
+        {
+            ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
+        }
 
         Try
         {
@@ -142,7 +152,7 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
 
     // Check whether there are more files to extract
     if (++m_zipIterator == m_zip->end()) {
-        LogDebug("Unzip progress finished successfuly");
+        _D("Unzip progress finished successfuly");
     } else {
         unzipProgress(destination);
     }
@@ -150,7 +160,7 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
 
 bool WidgetUnzip::isDRMPackage(const std::string &source)
 {
-    LogDebug("Enter : isDRMPackage()");
+    _D("Enter : isDRMPackage()");
     int ret = 0;
     void* pHandle = NULL;
     char* pErrorMsg = NULL;
@@ -158,15 +168,24 @@ bool WidgetUnzip::isDRMPackage(const std::string &source)
 
     pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
     if (!pHandle) {
-        LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+        _E("dlopen failed : %s [%s]", source.c_str(), dlerror());
         return false;
     }
 
+    // clear existing error
+    dlerror();
+
     drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>
         (dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
-    pErrorMsg = dlerror();
-    if ((pErrorMsg != NULL) || (drm_oem_sapps_is_drm_file == NULL)) {
-        LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+
+    if ((pErrorMsg = dlerror()) != NULL) {
+        _E("dlsym failed : %s [%s]", source.c_str(), pErrorMsg);
+        dlclose(pHandle);
+        return false;
+    }
+
+    if (drm_oem_sapps_is_drm_file == NULL) {
+        _E("drm_oem_sapps_is_drm_file is NULL : %s", source.c_str());
         dlclose(pHandle);
         return false;
     }
@@ -174,17 +193,17 @@ bool WidgetUnzip::isDRMPackage(const std::string &source)
     ret = drm_oem_sapps_is_drm_file(source.c_str(), source.length());
     dlclose(pHandle);
     if (1 == ret) {
-        LogDebug(source << " is DRM file");
+        _D("%s is DRM file", source.c_str());
         return true;
     }
-    LogDebug(source << " isn't DRM file");
+    _D("%s isn't DRM file", source.c_str());
     return false;
 }
 
 bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
         &decryptedSource)
 {
-    LogDebug("Enter : decryptDRMPackage()");
+    _D("Enter : decryptDRMPackage()");
     int ret = 0;
     void* pHandle = NULL;
     char* pErrorMsg = NULL;
@@ -193,16 +212,25 @@ bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
 
     pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
     if (!pHandle) {
-        LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+        _E("dlopen failed : %s [%s]", source.c_str(), dlerror());
         return false;
     }
 
+    // clear existing error
+    dlerror();
+
     drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int,
             const char*, int)>
         (dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
-    pErrorMsg = dlerror();
-    if ((pErrorMsg != NULL) || (drm_oem_sapps_decrypt_package == NULL)) {
-        LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+
+    if ((pErrorMsg = dlerror()) != NULL) {
+        _E("dlsym failed : %s [%s]", source.c_str(), pErrorMsg);
+        dlclose(pHandle);
+        return false;
+    }
+
+    if (drm_oem_sapps_decrypt_package == NULL) {
+        _E("drm_oem_sapps_decrypt_package is NULL : %s", source.c_str());
         dlclose(pHandle);
         return false;
     }
@@ -211,7 +239,7 @@ bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
             decryptedSource.c_str(), decryptedSource.length());
     dlclose(pHandle);
     if (1 == ret) {
-        LogDebug(source << " is decrypted : " << decryptedSource);
+        _D("%s is decrypted : %s", source.c_str(), decryptedSource.c_str());
         return true;
     }
     return false;
@@ -219,7 +247,7 @@ bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
 
 std::string WidgetUnzip::getDecryptedPackage(const std::string &source)
 {
-    LogDebug("Check DRM...");
+    _D("Check DRM...");
     if (isDRMPackage(source)) {
         std::string decryptedFile;
         size_t found = source.find_last_of(".wgt");
@@ -230,9 +258,9 @@ std::string WidgetUnzip::getDecryptedPackage(const std::string &source)
                     1) + "_tmp.wgt";
         }
 
-        LogDebug("decrypted file name : " << decryptedFile);
+        _D("decrypted file name : %s", decryptedFile.c_str());
         if (!decryptDRMPackage(source, decryptedFile)) {
-            LogError("Failed decrypt drm file");
+            _E("Failed decrypt drm file");
             ThrowMsg(Exceptions::DrmDecryptFailed, source);
         }
         return decryptedFile;
@@ -242,15 +270,16 @@ std::string WidgetUnzip::getDecryptedPackage(const std::string &source)
 
 void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &destination)
 {
-    LogDebug("Prepare to unzip...");
+    _D("Prepare to unzip...");
     std::string wgtFile;
     Try
     {
         wgtFile = getDecryptedPackage(source);
-        LogDebug("wgtFile : " << wgtFile);
+        _D("wgtFile : %s", wgtFile.c_str());
 
         m_zip.reset(new DPL::ZipInput(wgtFile));
-        LogDebug("Widget package comment: " << m_zip->GetGlobalComment());
+        _D("Widget package comment: %s", m_zip->GetGlobalComment().c_str());
+
 
         // Widget package must not be empty
         if (m_zip->empty()) {
@@ -266,7 +295,7 @@ void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &des
         m_zip.reset();
 
         // Done
-        LogDebug("Unzip finished");
+        _D("Unzip finished");
     }
     Catch(DPL::ZipInput::Exception::OpenFailed)
     {