Install failure during RDS update
authorsung-su.kim <sung-su.kim@samsung.com>
Fri, 16 Aug 2013 04:18:38 +0000 (13:18 +0900)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Tue, 20 Aug 2013 12:29:38 +0000 (21:29 +0900)
- RDS (Rapid Development Support): This feature supports fast updating with IDE.
  When a few sources are updated/changed, application doesn't need full update.

[Issue]    N/A
[Problem]  When a new file needs to be added which also includes a new directory,
           then the installer cannot handle them.
[Cause]    Missing logic to parse the newly created directory in the destination path.
[Solution] Add logic to create directory and then create file when necessary.
[SCMRequest] N/A

Change-Id: Ifd8fb2808773127dca09c95db3efb50d27424e52

src/jobs/widget_install/task_prepare_reinstall.cpp

index 7178db3..8955c19 100644 (file)
@@ -30,6 +30,7 @@
 #include <dpl/string.h>
 #include <dpl/log/log.h>
 #include <dpl/foreach.h>
+#include <dpl/utils/wrt_utility.h>
 
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
@@ -49,7 +50,27 @@ void verifyFile(const std::string &filePath)
         ThrowMsg(Exceptions::RDSDeltaFailure, "File is missed " << filePath);
     }
 }
+
+std::string parseSubPath(const std::string& filePath)
+{
+    std::string subPath("");
+    size_t pos = filePath.find_last_of('/') + 1;
+
+    if (pos != std::string::npos) {
+        subPath = filePath.substr(0, pos);
+    }
+    return subPath;
+}
+
+void createDir(const std::string& path)
+{
+    if (WrtUtilMakeDir(path)) {
+        LogDebug("Create directory : " << path);
+    } else {
+        ThrowMsg(Exceptions::RDSDeltaFailure, "Fail to create dir" << path);
+    }
 }
+} // namespace anonymous
 
 TaskPrepareReinstall::TaskPrepareReinstall(InstallerContext& context) :
     DPL::TaskDecl<TaskPrepareReinstall>(this),
@@ -154,11 +175,30 @@ void TaskPrepareReinstall::StepAddFile()
         newfile += *file;
         std::string destPath = m_installedPath;
         destPath += *file;
-        if (rename(newfile.c_str(), destPath.c_str()) != 0) {
-            ThrowMsg(Exceptions::RDSDeltaFailure,
-                "Fail to ADD file " << newfile);
+
+        if (WrtUtilDirExists(newfile)) {
+            // In case of a new directory
+            createDir(destPath);
+        } else {
+            // In case of a new file
+
+            // Parse directory and file separately
+            std::string subPath = parseSubPath(destPath);
+            if (subPath.empty()) {
+                ThrowMsg(Exceptions::RDSDeltaFailure,
+                         "Invalid path given" << destPath);
+            }
+
+            // Create a new directory
+            createDir(subPath);
+
+            // Add file
+            if (rename(newfile.c_str(), destPath.c_str()) != 0) {
+                ThrowMsg(Exceptions::RDSDeltaFailure,
+                        "Fail to add file " << newfile);
+            }
+            LogDebug("Add " << newfile << " to " << destPath);
         }
-        LogDebug("Copy " << newfile << " to " << destPath);
     }
 }