Revert "Clean up duplications with Dir operation"
authorHOSEON LEE <hoseon46.lee@samsung.com>
Wed, 23 Oct 2013 08:53:53 +0000 (08:53 +0000)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 23 Oct 2013 08:54:30 +0000 (08:54 +0000)
The permission of some files is changed when the app is updated.
(app -> root)
For this reason, the app is not launched after updated.
Please check again it and make a commit.

This reverts commit af8ac24f7ac6d6ecef023da2503cafbbc854d18a.

Change-Id: I46ddb01b0b4531662328f7e092e7b1658183d00e

14 files changed:
src/CMakeLists.txt
src/configuration_parser/widget_parser.cpp
src/jobs/widget_install/directory_api.cpp [new file with mode: 0644]
src/jobs/widget_install/directory_api.h [new file with mode: 0644]
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/task_commons.cpp [new file with mode: 0644]
src/jobs/widget_install/task_commons.h [new file with mode: 0644]
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 11ecb08..8009d61 100644 (file)
@@ -61,6 +61,7 @@ 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
@@ -81,6 +82,7 @@ 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 2503c8d..e8b832d 100644 (file)
@@ -1340,8 +1340,6 @@ 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
new file mode 100644 (file)
index 0000000..dd8aa07
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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
new file mode 100644 (file)
index 0000000..1632528
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 55ab2c0..bd43f8d 100644 (file)
@@ -53,6 +53,7 @@
 #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
new file mode 100644 (file)
index 0000000..c5b5b67
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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
new file mode 100644 (file)
index 0000000..caf9660
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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 4dd66ca..bec432c 100644 (file)
@@ -51,6 +51,7 @@
 #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,11 +71,22 @@ 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";
+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));
+}
 } // namespace anonymous
 
 namespace Jobs {
@@ -142,33 +154,25 @@ std::shared_ptr<PackageManager::IPkgmgrSignal> TaskConfiguration::pkgMgrInterfac
 void TaskConfiguration::SetupTempDirStep()
 {
     _D("widgetPath: %s", m_context.requestedPath.c_str());
-    if (m_context.mode.extension == InstallMode::ExtensionType::DIR)
-    {
-        if(m_context.mode.command == InstallMode::Command::REINSTALL)
-        {
+    _D("tempPath: %s", m_tempDir.c_str());
+    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
+        } else {
             m_tempDir = m_context.requestedPath;
-    }
-    else
-    {
+        }
+    } else {
         m_tempDir =
-                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))
+            Jobs::WidgetInstall::createTempPath(
+                    m_context.mode.rootPath ==
+                        InstallMode::RootPath::RO);
+        if(!hasExtension(m_context.requestedPath, XML_EXTENSION)) //unzip everything except xml files
         {
             WidgetUnzip wgtUnzip;
             wgtUnzip.unzipWgtFile(m_context.requestedPath, m_tempDir);
@@ -178,8 +182,6 @@ void TaskConfiguration::SetupTempDirStep()
             _D("From browser installation - unzip is not done");
         }
     }
-
-    _D("tempPath: %s", m_tempDir.c_str());
 }
 
 void TaskConfiguration::ParseXMLConfigStep()
@@ -577,7 +579,7 @@ WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
 
 void TaskConfiguration::CheckPackageTypeStep()
 {
-    if (DPL::Utils::Path(m_context.requestedPath).hasExtension(XML_EXTENSION)){
+    if (hasExtension(m_context.requestedPath, XML_EXTENSION)) {
         _D("Hosted app installation");
         m_context.widgetConfig.packagingType = PKG_TYPE_HOSTED_WEB_APP;
         return;
index 77378af..a9dff14 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_to_external.h>
-
+#include <widget_install/directory_api.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>
@@ -55,6 +51,54 @@ 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)) {
@@ -160,22 +204,17 @@ void TaskFileManipulation::StepCreateDirs()
 void TaskFileManipulation::StepCreatePrivateStorageDir()
 {
     std::string storagePath = m_context.locations->getPrivateStorageDir();
-    _D("Create private storage directory : %s", storagePath.c_str());
+    _D("Create private storage directory : %s", m_context.locations->getPrivateStorageDir().c_str());
 
     changeOwnerForDirectory(storagePath, PRIVATE_STORAGE_MODE);
 
     if (m_context.isUpdateMode) { //update
-        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");
+        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");
         }
     }
 
@@ -338,27 +377,19 @@ void TaskFileManipulation::StepPrepareExternalDir()
 
 void TaskFileManipulation::StepInstallToExternal()
 {
-    std::string sourceDir = m_context.locations->getSourceDir();
     _D("StepInstallExternal");
-    if (!WrtUtilMakeDir(sourceDir)) {
+    if (!WrtUtilMakeDir(m_context.locations->getSourceDir())) {
         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("Copy shared storage %s to %s", from.Fullpath().c_str(), to.Fullpath().c_str());
-
-    Try
+    _D("Resource move to external storage %s", m_context.locations->getSourceDir().c_str());
+    if (!_FolderCopy(m_context.locations->getTemporaryPackageDir(),
+                     m_context.locations->getSourceDir()))
     {
-        DPL::Utils::CopyDir(from, to);
-    }
-    Catch(DPL::Utils::Path::BaseException)
-    {
-        ThrowMsg(Exceptions::ErrorExternalInstallingFailure, "Error occurs during renaming widget folder");
+        ThrowMsg(Exceptions::ErrorExternalInstallingFailure,
+                 "Error occurs during renaming widget folder");
     }
 }
 
@@ -377,7 +408,7 @@ void TaskFileManipulation::StepCreateSharedFolder()
 {
     _D("StepCreateSharedFolder");
     std::string sharedPath = m_context.locations->getSharedRootDir();
-    _D("Create shared directory : %s", sharedPath.c_str());
+    _D("Create shared directory : %s", m_context.locations->getSharedRootDir().c_str());
 
     WrtUtilMakeDir(sharedPath);
     WrtUtilMakeDir(m_context.locations->getSharedResourceDir());
@@ -387,37 +418,32 @@ 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", 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");
-        }
+        _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");
+            }
 
         /* Restore /shared/trusted */
-        _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");
+        _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");
         }
     }
 }
index bd52dd2..ccd8ebf 100644 (file)
@@ -30,6 +30,7 @@
 #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 e7bb5a9..10caf9e 100644 (file)
@@ -28,7 +28,6 @@
 #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>
@@ -71,11 +70,6 @@ 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 9a11df6..91ab30c 100644 (file)
@@ -36,6 +36,7 @@
 #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 d41b890..8a7f601 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,14 +106,7 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
         _D("Path to extract: %s", newPath.c_str());
 
         // Create path in case of it is empty
-        Try
-        {
-            DPL::Utils::MakeDir(DPL::Utils::Path(newPath));
-        }
-        Catch(DPL::Utils::Path::BaseException)
-        {
-            ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
-        }
+        createTempPath(newPath);
     } else {
         // This is regular file
         std::string fileExtractPath = destination + "/" + fileName;
@@ -126,14 +119,7 @@ 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
-        Try
-        {
-            DPL::Utils::MakeDir(DPL::Utils::Path(pathAndFile.path));
-        }
-        Catch(DPL::Utils::Path::BaseException)
-        {
-            ThrowMsg(Exceptions::FileOperationFailed, "Failed to create temporary directory");
-        }
+        createTempPath(pathAndFile.path);
 
         Try
         {
index 6e6b6be..8ab5fef 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(DPL::Utils::CreateTempPath(
-        DPL::Utils::Path(
-            isReadOnly ?
-                WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()
-            :
-                WrtDB::GlobalConfig::GetUserInstalledWidgetPath()
-        )
-    ).Fullpath())
+    m_dirpath(Jobs::WidgetInstall::createTempPath(isReadOnly))
 {}
 
 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
-    m_dirpath(tempPath)
+        m_dirpath(tempPath)
 {}
 
 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()