Clean up duplications with Dir operation
authorMaciej Piotrowski <m.piotrowski@samsung.com>
Tue, 27 Aug 2013 11:50:46 +0000 (13:50 +0200)
committerMaciej Piotrowski <m.piotrowski@samsung.com>
Mon, 21 Oct 2013 07:55:59 +0000 (09:55 +0200)
[Issue#]   LINUXWRT-717
[Problem]  Dir operation duplications.
[Cause]    N/A
[Solution] Functionality from
            - wrt-installer/src/jobs/widget_install/directory_api.*
            - wrt-installer/src/jobs/widget_install/task_common.*
            was transferred to wrt-commons/modules/utils/src/path.cpp

It was checked if wrt-installer/src/jobs/widget_install/task_file_manipulation.cpp
contains any duplicate code, and small changes were applied to it.

[SCMRequest] Depends on https://review.tizendev.org/gerrit/#/c/86370/

[Verification] 1. Build repository
               2. Normal installation [wgt]
               3. Normal installation update [wgt]
               4. install wrt-extra on target and run:
                  wrt-installer -i /opt/share/widget/tests/widgetstest/config.xml

Change-Id: If39cf5b184f97fdec2b49908873a2cc6b27f1d5d

14 files changed:
src/CMakeLists.txt
src/configuration_parser/widget_parser.cpp
src/jobs/widget_install/directory_api.cpp [deleted file]
src/jobs/widget_install/directory_api.h [deleted file]
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/task_commons.cpp [deleted file]
src/jobs/widget_install/task_commons.h [deleted file]
src/jobs/widget_install/task_configuration.cpp
src/jobs/widget_install/task_file_manipulation.cpp
src/jobs/widget_install/task_prepare_files.cpp
src/jobs/widget_install/task_remove_backup.cpp
src/jobs/widget_install/task_update_files.cpp
src/jobs/widget_install/widget_unzip.cpp
src/misc/widget_location.cpp

index 8009d61..11ecb08 100644 (file)
@@ -61,7 +61,6 @@ SET(INSTALLER_SOURCES
     ${INSTALLER_JOBS}/plugin_install/plugin_metafile_reader.cpp
     ${INSTALLER_JOBS}/widget_install/job_widget_install.cpp
     ${INSTALLER_JOBS}/widget_install/manifest.cpp
-    ${INSTALLER_JOBS}/widget_install/task_commons.cpp
     ${INSTALLER_JOBS}/widget_install/task_process_config.cpp
     ${INSTALLER_JOBS}/widget_install/task_database.cpp
     ${INSTALLER_JOBS}/widget_install/task_configuration.cpp
@@ -82,7 +81,6 @@ SET(INSTALLER_SOURCES
     ${INSTALLER_JOBS}/widget_install/task_pkg_info_update.cpp
     ${INSTALLER_JOBS}/widget_install/widget_security.cpp
     ${INSTALLER_JOBS}/widget_install/widget_update_info.cpp
-    ${INSTALLER_JOBS}/widget_install/directory_api.cpp
     ${INSTALLER_JOBS}/widget_install/widget_unzip.cpp
     ${INSTALLER_JOBS}/widget_uninstall/job_widget_uninstall.cpp
     ${INSTALLER_JOBS}/widget_uninstall/task_check.cpp
index 768003b..62a640e 100644 (file)
@@ -1305,6 +1305,8 @@ class ApplicationParser : public ElementParser
             pcrecpp::RE re(REGEXP_ID);
             if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
             {
+                _D("package: %s | m_package: %s | m_id: %s",
+                        package.c_str(), DPL::ToUTF8String(*m_package).c_str(), DPL::ToUTF8String(*m_id).c_str());
                 ThrowMsg(Exception::ParseError,
                          "invalid format of id attribute");
             }
diff --git a/src/jobs/widget_install/directory_api.cpp b/src/jobs/widget_install/directory_api.cpp
deleted file mode 100644 (file)
index dd8aa07..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/**
- * @file    directory_api.cpp
- * @author  Soyoung Kim(sy037.kim@samsung.com)
- * @version 1.0
- * @brief   directory api - implementation file
- */
-
-#include <cerrno>
-#include <directory_api.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <fstream>
-#include <dpl/foreach.h>
-#include <dpl/utils/wrt_utility.h>
-#include <dpl/errno_string.h>
-#include <installer_log.h>
-
-namespace DirectoryApi {
-bool DirectoryCopy(std::string source, std::string dest)
-{
-    DIR* dir = opendir(source.c_str());
-    if (NULL == dir) {
-        return false;
-    }
-
-    struct dirent dEntry;
-    struct dirent *dEntryResult;
-    int return_code;
-
-    do {
-        struct stat statInfo;
-        return_code = readdir_r(dir, &dEntry, &dEntryResult);
-        if (dEntryResult != NULL && return_code == 0) {
-            std::string fileName = dEntry.d_name;
-            std::string fullName = source + "/" + fileName;
-
-            if (stat(fullName.c_str(), &statInfo) != 0) {
-                closedir(dir);
-                return false;
-            }
-
-            if (S_ISDIR(statInfo.st_mode)) {
-                if (("." == fileName) || (".." == fileName)) {
-                    continue;
-                }
-                std::string destFolder = dest + "/" + fileName;
-                WrtUtilMakeDir(destFolder);
-
-                if (!DirectoryCopy(fullName, destFolder)) {
-                    closedir(dir);
-                    return false;
-                }
-            }
-
-            std::string destFile = dest + "/" + fileName;
-            std::ifstream infile(fullName);
-            std::ofstream outfile(destFile);
-            outfile << infile.rdbuf();
-            outfile.close();
-            infile.close();
-
-            errno = 0;
-            if (-1 == TEMP_FAILURE_RETRY(chown(destFile.c_str(),
-                                               statInfo.st_uid,
-                                               statInfo.st_gid))) {
-                int error = errno;
-                _E("Failed to change owner [%s]", DPL::GetErrnoString(error).c_str());
-            }
-        }
-    } while (dEntryResult != NULL && return_code == 0);
-    closedir(dir);
-    return true;
-}
-}
diff --git a/src/jobs/widget_install/directory_api.h b/src/jobs/widget_install/directory_api.h
deleted file mode 100644 (file)
index 1632528..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/**
- * @file    directory_api.h
- * @author  Soyoung Kim(sy037.kim@samsung.com)
- * @version 1.0
- * @brief   directory api - header file
- */
-#ifndef WRT_SRC_INSTALLER_CORE_DIRECTORY_API_H_
-#define WRT_SRC_INSTALLER_CORE_DIRECTORY_API_H_
-
-#include<string>
-
-namespace DirectoryApi {
-bool DirectoryCopy(std::string source, std::string dest);
-}
-
-#endif  /* WRT_SRC_INSTALLER_CORE_DIRECTORY_API_H_ */
-
index bd43f8d..55ab2c0 100644 (file)
@@ -53,7 +53,6 @@
 #include <widget_install/task_remove_backup.h>
 #include <widget_install/task_encrypt_resource.h>
 #include <widget_install/task_pkg_info_update.h>
-#include <widget_install/task_commons.h>
 #include <widget_install/task_prepare_reinstall.h>
 #include <widget_install/task_configuration.h>
 
diff --git a/src/jobs/widget_install/task_commons.cpp b/src/jobs/widget_install/task_commons.cpp
deleted file mode 100644 (file)
index c5b5b67..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file       task_commons.cpp
- * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
- * @version    1.0
- */
-
-#include "task_commons.h"
-#include <unistd.h>
-#include <sstream>
-#include <ftw.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <dpl/wrt-dao-ro/global_config.h>
-#include <dpl/exception.h>
-#include <dpl/errno_string.h>
-#include <dpl/utils/wrt_utility.h>
-#include <widget_install/widget_install_errors.h>
-#include <installer_log.h>
-
-namespace Jobs {
-namespace WidgetInstall {
-namespace {
-const char * const TEMPORARY_PATH_POSTFIX = "temp";
-const mode_t TEMPORARY_PATH_MODE = 0775;
-} // namespace
-
-std::string createTempPath(bool preload)
-{
-    _D("Step: Creating temporary path");
-
-    // Temporary path
-    std::ostringstream tempPathBuilder;
-
-    if (preload) {
-        tempPathBuilder << WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
-    } else {
-        tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
-    }
-    tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
-    tempPathBuilder << "/";
-    tempPathBuilder << TEMPORARY_PATH_POSTFIX;
-    tempPathBuilder << "_";
-
-    timeval tv;
-    gettimeofday(&tv, NULL);
-    tempPathBuilder <<
-    (static_cast<unsigned long long>(tv.tv_sec) * 1000000ULL +
-     static_cast<unsigned long long>(tv.tv_usec));
-
-    std::string tempPath = tempPathBuilder.str();
-
-    // Remove old path if any
-    struct stat fileInfo;
-
-    if (stat(tempPath.c_str(), &fileInfo) == 0) {
-        if (!WrtUtilRemove(tempPath)) {
-            ThrowMsg(Exceptions::RemovingFolderFailure,
-                     "Failed to to remove temporary directory");
-        }
-    }
-    // Create new path
-    if (!WrtUtilMakeDir(tempPath, TEMPORARY_PATH_MODE)) {
-        ThrowMsg(Exceptions::FileOperationFailed,
-                 "Failed to create temporary directory");
-    }
-
-    return tempPath;
-}
-
-void createTempPath(const std::string& path)
-{
-    if (!WrtUtilMakeDir(path, TEMPORARY_PATH_MODE)) {
-        ThrowMsg(Exceptions::FileOperationFailed,
-                 "Failed to create temporary directory");
-    }
-}
-} // WidgetInstall
-} // Jobs
diff --git a/src/jobs/widget_install/task_commons.h b/src/jobs/widget_install/task_commons.h
deleted file mode 100644 (file)
index caf9660..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file       task_commons.h
- * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
- * @version    1.0
- */
-
-#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_COMMONS_H_
-#define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_COMMONS_H_
-
-#include <string>
-
-namespace Jobs {
-namespace WidgetInstall {
-//TODO make directory like jobs common?
-
-std::string createTempPath(bool isReadOnly = false);
-void createTempPath(const std::string& path);
-} // WidgetInstall
-} // Jobs
-
-#endif /* INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_COMMONS_H_ */
index 978a9af..f584ff9 100644 (file)
@@ -51,7 +51,6 @@
 #include <widget_install_to_external.h>
 #include <widget_install/widget_unzip.h>
 #include <widget_install/job_widget_install.h>
-#include <widget_install/task_commons.h>
 
 #include <installer_log.h>
 
@@ -70,22 +69,11 @@ const size_t PACKAGE_ID_LENGTH = 10;
 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
 static const DPL::String SETTING_VALUE_ENCRYPTION_DISABLE = L"disable";
+
 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME = L"install-location";
 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT = L"prefer-external";
 const DPL::String SETTING_VALUE_INSTALLTOEXT_AUTO = L"auto";
-const std::string XML_EXTENSION = ".xml";
-
-bool hasExtension(const std::string& filename, const std::string& extension)
-{
-    _D("Looking for extension %s in %s", extension.c_str(), filename.c_str());
-    size_t fileLen = filename.length();
-    size_t extLen = extension.length();
-    if (fileLen < extLen) {
-        _E("Filename %s is shorter than extension %s", filename.c_str(), extension.c_str());
-        return false;
-    }
-    return (0 == filename.compare(fileLen - extLen, extLen, extension));
-}
+const std::string XML_EXTENSION = "xml";
 } // namespace anonymous
 
 namespace Jobs {
@@ -153,25 +141,33 @@ std::shared_ptr<PackageManager::IPkgmgrSignal> TaskConfiguration::pkgMgrInterfac
 void TaskConfiguration::SetupTempDirStep()
 {
     _D("widgetPath: %s", m_context.requestedPath.c_str());
-    _D("tempPath: %s", m_tempDir.c_str());
-    if (m_context.mode.extension == InstallMode::ExtensionType::DIR) {
-        if (m_context.mode.command ==
-                InstallMode::Command::REINSTALL) {
+    if (m_context.mode.extension == InstallMode::ExtensionType::DIR)
+    {
+        if(m_context.mode.command == InstallMode::Command::REINSTALL)
+        {
             std::ostringstream tempPathBuilder;
             tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
             tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
             tempPathBuilder << "/";
             tempPathBuilder << m_context.requestedPath;
             m_tempDir = tempPathBuilder.str();
-        } else {
-            m_tempDir = m_context.requestedPath;
         }
-    } else {
+        else
+            m_tempDir = m_context.requestedPath;
+    }
+    else
+    {
         m_tempDir =
-            Jobs::WidgetInstall::createTempPath(
-                    m_context.mode.rootPath ==
-                        InstallMode::RootPath::RO);
-        if(!hasExtension(m_context.requestedPath, XML_EXTENSION)) //unzip everything except xml files
+                DPL::Utils::CreateTempPath(
+                    DPL::Utils::Path(
+                        m_context.mode.rootPath == InstallMode::RootPath::RO ?
+                            WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()
+                        :
+                            WrtDB::GlobalConfig::GetUserInstalledWidgetPath()
+                    )
+                ).Fullpath();
+
+        if(!DPL::Utils::Path(m_context.requestedPath).hasExtension(XML_EXTENSION))
         {
             WidgetUnzip wgtUnzip;
             wgtUnzip.unzipWgtFile(m_context.requestedPath, m_tempDir);
@@ -181,6 +177,8 @@ void TaskConfiguration::SetupTempDirStep()
             _D("From browser installation - unzip is not done");
         }
     }
+
+    _D("tempPath: %s", m_tempDir.c_str());
 }
 
 void TaskConfiguration::ParseXMLConfigStep()
@@ -574,7 +572,7 @@ WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
 
 void TaskConfiguration::CheckPackageTypeStep()
 {
-    if (hasExtension(m_context.requestedPath, XML_EXTENSION)) {
+    if (DPL::Utils::Path(m_context.requestedPath).hasExtension(XML_EXTENSION)){
         _D("Hosted app installation");
         m_context.widgetConfig.packagingType = PKG_TYPE_HOSTED_WEB_APP;
         return;
index a9dff14..77378af 100644 (file)
 #include <unistd.h>
 #include <sys/stat.h>
 #include <dirent.h>
+
 #include <widget_install/task_file_manipulation.h>
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
-#include <widget_install/directory_api.h>
+#include <widget_install_to_external.h>
+
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/foreach.h>
 #include <dpl/assert.h>
 #include <dpl/errno_string.h>
 #include <dpl/utils/folder_size.h>
+#include <dpl/utils/path.h>
 #include <dpl/wrt-dao-ro/global_config.h>
+
 #include <string>
 #include <fstream>
 #include <widget_install_to_external.h>
@@ -51,54 +55,6 @@ using namespace WrtDB;
 namespace {
 const char* GLIST_RES_DIR = "res";
 
-bool _FolderCopy(std::string source, std::string dest)
-{
-    DIR* dir = opendir(source.c_str());
-    if (NULL == dir) {
-        return false;
-    }
-
-    struct dirent dEntry;
-    struct dirent *dEntryResult;
-    int return_code;
-
-    do {
-        struct stat statInfo;
-        return_code = readdir_r(dir, &dEntry, &dEntryResult);
-        if (dEntryResult != NULL && return_code == 0) {
-            std::string fileName = dEntry.d_name;
-            std::string fullName = source + "/" + fileName;
-
-            if (stat(fullName.c_str(), &statInfo) != 0) {
-                closedir(dir);
-                return false;
-            }
-
-            if (S_ISDIR(statInfo.st_mode)) {
-                if (("." == fileName) || (".." == fileName)) {
-                    continue;
-                }
-                std::string destFolder = dest + "/" + fileName;
-                WrtUtilMakeDir(destFolder);
-
-                if (!_FolderCopy(fullName, destFolder)) {
-                    closedir(dir);
-                    return false;
-                }
-            }
-
-            std::string destFile = dest + "/" + fileName;
-            std::ifstream infile(fullName);
-            std::ofstream outfile(destFile);
-            outfile << infile.rdbuf();
-            outfile.close();
-            infile.close();
-        }
-    } while (dEntryResult != NULL && return_code == 0);
-    closedir(dir);
-    return true;
-}
-
 void changeOwnerForDirectory(std::string storagePath, mode_t mode) {
     if (euidaccess(storagePath.c_str(), F_OK) != 0) {
         if (!WrtUtilMakeDir(storagePath, mode)) {
@@ -204,17 +160,22 @@ void TaskFileManipulation::StepCreateDirs()
 void TaskFileManipulation::StepCreatePrivateStorageDir()
 {
     std::string storagePath = m_context.locations->getPrivateStorageDir();
-    _D("Create private storage directory : %s", m_context.locations->getPrivateStorageDir().c_str());
+    _D("Create private storage directory : %s", storagePath.c_str());
 
     changeOwnerForDirectory(storagePath, PRIVATE_STORAGE_MODE);
 
     if (m_context.isUpdateMode) { //update
-        std::string backData = m_context.locations->getBackupPrivateDir();
-        _D("copy private storage %s to %s", backData.c_str(), storagePath.c_str());
-        if (!DirectoryApi::DirectoryCopy(backData, storagePath)) {
-            _E("Failed to rename %s to %s", backData.c_str(), storagePath.c_str());
-            ThrowMsg(Exceptions::BackupFailed,
-                    "Error occurs copy private strage files");
+        DPL::Utils::Path backData = DPL::Utils::Path(m_context.locations->getBackupPrivateDir());
+        DPL::Utils::Path storageData = DPL::Utils::Path(storagePath);
+        _D("copy private storage %s to %s", backData.Fullpath().c_str(), storageData.Fullpath().c_str());
+
+        Try
+        {
+            DPL::Utils::CopyDir(backData, storageData);
+        }
+        Catch(DPL::Utils::Path::BaseException)
+        {
+            ThrowMsg(Exceptions::BackupFailed, "Error occurs copy private storage files");
         }
     }
 
@@ -377,19 +338,27 @@ void TaskFileManipulation::StepPrepareExternalDir()
 
 void TaskFileManipulation::StepInstallToExternal()
 {
+    std::string sourceDir = m_context.locations->getSourceDir();
     _D("StepInstallExternal");
-    if (!WrtUtilMakeDir(m_context.locations->getSourceDir())) {
+    if (!WrtUtilMakeDir(sourceDir)) {
         ThrowMsg(Exceptions::ErrorExternalInstallingFailure,
                  "To make src \
                 directory failed");
     }
+    _D("Resource move to external storage %s", sourceDir.c_str());
+
+    DPL::Utils::Path from = DPL::Utils::Path(m_context.locations->getTemporaryPackageDir());
+    DPL::Utils::Path to = DPL::Utils::Path(sourceDir);
 
-    _D("Resource move to external storage %s", m_context.locations->getSourceDir().c_str());
-    if (!_FolderCopy(m_context.locations->getTemporaryPackageDir(),
-                     m_context.locations->getSourceDir()))
+    _D("Copy shared storage %s to %s", from.Fullpath().c_str(), to.Fullpath().c_str());
+
+    Try
     {
-        ThrowMsg(Exceptions::ErrorExternalInstallingFailure,
-                 "Error occurs during renaming widget folder");
+        DPL::Utils::CopyDir(from, to);
+    }
+    Catch(DPL::Utils::Path::BaseException)
+    {
+        ThrowMsg(Exceptions::ErrorExternalInstallingFailure, "Error occurs during renaming widget folder");
     }
 }
 
@@ -408,7 +377,7 @@ void TaskFileManipulation::StepCreateSharedFolder()
 {
     _D("StepCreateSharedFolder");
     std::string sharedPath = m_context.locations->getSharedRootDir();
-    _D("Create shared directory : %s", m_context.locations->getSharedRootDir().c_str());
+    _D("Create shared directory : %s", sharedPath.c_str());
 
     WrtUtilMakeDir(sharedPath);
     WrtUtilMakeDir(m_context.locations->getSharedResourceDir());
@@ -418,32 +387,37 @@ void TaskFileManipulation::StepCreateSharedFolder()
     changeOwnerForDirectory(m_context.locations->getSharedTrustedDir(),
             SHARED_STORAGE_MODE);
 
-
     // additional check for rootPath installation
     // If this app is preloaded, "shared" diretory is already on place and do not needs to be moved
     // TODO: why "shared" is on RW partion always but "data" and "tmp" are linked
     if (m_context.isUpdateMode
             && !(m_context.mode.rootPath == InstallMode::RootPath::RO
             && m_context.mode.installTime == InstallMode::InstallTime::PRELOAD)) {
+        DPL::Utils::Path backData = DPL::Utils::Path(m_context.locations->getBackupSharedDataDir());
+        DPL::Utils::Path sharedData = DPL::Utils::Path(m_context.locations->getSharedDataDir());
+        DPL::Utils::Path backTrusted = DPL::Utils::Path(m_context.locations->getBackupSharedTrustedDir());
+        DPL::Utils::Path sharedTrusted = DPL::Utils::Path(m_context.locations->getSharedTrustedDir());
 
         /* Restore /shared/data */
-        _D("copy %s to %s", m_context.locations->getBackupSharedDataDir().c_str(), m_context.locations->getSharedDataDir().c_str());
-        if (!DirectoryApi::DirectoryCopy(
-                    m_context.locations->getBackupSharedDataDir(),
-                    m_context.locations->getSharedDataDir())) {
-                _E("Failed to rename %s to %s", m_context.locations->getBackupSharedDataDir().c_str(), m_context.locations->getSharedDataDir().c_str());
-                ThrowMsg(Exceptions::BackupFailed,
-                        "Error occurs copy shared strage files");
-            }
+        _D("Copy %s to %s", backData.Fullpath().c_str(), sharedData.Fullpath().c_str());
+        Try
+        {
+            DPL::Utils::CopyDir(backData, sharedData);
+        }
+        Catch(DPL::Utils::Path::BaseException)
+        {
+            ThrowMsg(Exceptions::BackupFailed, "Error occurs copy shared storage files");
+        }
 
         /* Restore /shared/trusted */
-        _D("copy %s to %s", m_context.locations->getBackupSharedTrustedDir().c_str(), m_context.locations->getSharedTrustedDir().c_str());
-        if (!DirectoryApi::DirectoryCopy(
-                    m_context.locations->getBackupSharedTrustedDir(),
-                    m_context.locations->getSharedTrustedDir())) {
-            _E("Failed to rename %s to %s", m_context.locations->getBackupSharedTrustedDir().c_str(), m_context.locations->getSharedTrustedDir().c_str());
-            ThrowMsg(Exceptions::BackupFailed,
-                    "Error occurs copy shared strage files");
+        _D("Copy %s to %s", backTrusted.Fullpath().c_str(), sharedTrusted.Fullpath().c_str());
+        Try
+        {
+            DPL::Utils::CopyDir(backTrusted, sharedTrusted);
+        }
+        Catch(DPL::Utils::Path::BaseException)
+        {
+            ThrowMsg(Exceptions::BackupFailed, "Error occurs copy shared storage files");
         }
     }
 }
index ccd8ebf..bd52dd2 100644 (file)
@@ -30,7 +30,6 @@
 #include <dpl/foreach.h>
 #include <widget_install/widget_install_context.h>
 #include <widget_install_errors.h>
-#include <task_commons.h>
 #include <installer_log.h>
 
 namespace Jobs {
index 10caf9e..e7bb5a9 100644 (file)
@@ -28,6 +28,7 @@
 #include <dpl/foreach.h>
 #include <dpl/assert.h>
 #include <dpl/utils/wrt_utility.h>
+#include <dpl/utils/path.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
@@ -70,6 +71,11 @@ void TaskRemoveBackupFiles::StepRemoveBackupFiles()
     if (WrtUtilRemove(tmp)) {
         _D("Success to remove temp directory : %s", tmp.c_str());
     } else {
+        if (!DPL::Utils::Exists(DPL::Utils::Path(tmp)))
+            _E("Temp directory doesn't exist : %s", tmp.c_str());
+        else
+            _D("Temp directory exists : %s", tmp.c_str());
+
         _E("Failed to remove temp directory : %s", tmp.c_str());
     }
 }
index 91ab30c..9a11df6 100644 (file)
@@ -36,7 +36,6 @@
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/job_widget_install.h>
-#include <widget_install/directory_api.h>
 
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/exception.h>
index 8a7f601..d41b890 100644 (file)
@@ -25,9 +25,9 @@
 #include <widget_install/job_widget_install.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>
@@ -106,7 +106,14 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
         _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;
@@ -119,7 +126,14 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
         _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
         {
index 8ab5fef..6e6b6be 100644 (file)
 #include "widget_location.h"
 
 #include <unistd.h>
+#include <dpl/utils/path.h>
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/assert.h>
 #include <dpl/sstream.h>
 #include <dpl/localization/localization_utils.h>
-#include <widget_install/task_commons.h>
 #include <installer_log.h>
 
 WidgetLocation::DirectoryDeletor::DirectoryDeletor(bool isReadOnly) :
-    m_dirpath(Jobs::WidgetInstall::createTempPath(isReadOnly))
+    m_dirpath(DPL::Utils::CreateTempPath(
+        DPL::Utils::Path(
+            isReadOnly ?
+                WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()
+            :
+                WrtDB::GlobalConfig::GetUserInstalledWidgetPath()
+        )
+    ).Fullpath())
 {}
 
 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
-        m_dirpath(tempPath)
+    m_dirpath(tempPath)
 {}
 
 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()