[Release] wrt-installer_0.1.53
[framework/web/wrt-installer.git] / src / misc / widget_location.cpp
index d6fff67..adfbd44 100644 (file)
 #include <dpl/log/log.h>
 #include <dpl/sstream.h>
 #include <dpl/localization/localization_utils.h>
-
 #include <widget_install/task_commons.h>
 
-WidgetLocation::DirectoryDeletor::DirectoryDeletor() :
-    m_dirpath(Jobs::WidgetInstall::createTempPath())
+WidgetLocation::DirectoryDeletor::DirectoryDeletor(bool isReadOnly) :
+    m_dirpath(Jobs::WidgetInstall::createTempPath(isReadOnly))
 {}
 
 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
@@ -41,7 +40,7 @@ WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
     LogDebug(
         "Removing widget installation temporary directory: " << m_dirpath.c_str());
     if (!WrtUtilRemove(m_dirpath)) {
-        LogError("Fail at removing directory: " << m_dirpath.c_str());
+        LogWarning("Fail at removing directory: " << m_dirpath.c_str());
     }
 }
 
@@ -63,35 +62,43 @@ WidgetLocation::~WidgetLocation()
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
                                WrtDB::PackagingType t,
-                               InstallLocationType locationType) :
+                               bool isReadonly) :
     m_pkgid(widgetname),
     m_widgetSource(sourcePath),
     m_type(t),
-    m_temp(new WidgetLocation::DirectoryDeletor())
+    m_temp(
+        new WidgetLocation::DirectoryDeletor(isReadonly))
 {
-    if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
+    if (isReadonly) {
         m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
     } else {
         m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
     }
+    // TODO clean-up
+    if (access(m_widgetSource.c_str(), F_OK) != 0) {
+        m_widgetSource = m_installedPath + "/" + m_pkgid;
+    }
 }
 
 WidgetLocation::WidgetLocation(const std::string & widgetname,
                                std::string sourcePath,
                                std::string dirPath,
                                WrtDB::PackagingType t,
-                               InstallLocationType locationType) :
+                               bool isReadonly) :
     m_pkgid(widgetname),
     m_widgetSource(sourcePath),
     m_type(t),
-    m_temp(new
-           WidgetLocation::DirectoryDeletor(dirPath))
+    m_temp(new WidgetLocation::DirectoryDeletor(dirPath))
 {
-    if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) {
+    if (isReadonly) {
         m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
     } else {
         m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
     }
+    // TODO clean-up
+    if (access(m_widgetSource.c_str(), F_OK) != 0) {
+        m_widgetSource = m_installedPath + "/" + m_pkgid;
+    }
 }
 
 // TODO cache all these paths
@@ -117,6 +124,12 @@ std::string WidgetLocation::getBinaryDir() const
            + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
 }
 
+std::string WidgetLocation::getUserBinaryDir() const
+{
+    return getUserDataRootDir() + "/"
+           + WrtDB::GlobalConfig::GetUserWidgetExecPath();
+}
+
 std::string WidgetLocation::getExecFile() const
 {
     return getBinaryDir() + "/" + m_appid;
@@ -124,7 +137,7 @@ std::string WidgetLocation::getExecFile() const
 
 std::string WidgetLocation::getBackupDir() const
 {
-    return getPackageInstallationDir() + "/backup";
+    return getPackageInstallationDir() + ".backup";
 }
 
 std::string WidgetLocation::getBackupSourceDir() const
@@ -142,6 +155,12 @@ std::string WidgetLocation::getBackupExecFile() const
     return getBackupBinaryDir() + "/" + m_appid;
 }
 
+std::string WidgetLocation::getBackupPrivateDir() const
+{
+    return getBackupDir() + "/" +
+        WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
+}
+
 std::string WidgetLocation::getUserDataRootDir() const
 {
     return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +