[Archive] Replace old virtual root path. 10/89410/3
authorTomasz Marciniak <t.marciniak@samsung.com>
Fri, 23 Sep 2016 10:25:02 +0000 (12:25 +0200)
committerTomasz Marciniak <t.marciniak@samsung.com>
Fri, 23 Sep 2016 12:25:31 +0000 (05:25 -0700)
[Verification] Code compiles.
TCT pass rate is 100% with change in inst.py script
which replaces "/home/owner/content/Downloads" to
"/opt/usr/home/owner/media/Downloads"

Change-Id: If567a4d30ee8e8382faf809e4f49687500c4e643
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/archive/filesystem_path.cc
src/archive/filesystem_path.h

index 1357a71..0b9a902 100755 (executable)
@@ -19,6 +19,8 @@
 #include <iterator>
 #include <stdlib.h>
 #include <limits.h>
+#include <tzplatform_variables.h>
+#include <tzplatform_config.h>
 
 #include "filesystem_path.h"
 #include "common/logger.h"
 namespace extension {
 namespace filesystem {
 
+#define MAX_PATH_SIZE 4096
+
 const Path::SeparatorType Path::m_pathSeparator = '/';
 
+std::string Path::replaceVirtualRootPath(const char* path) {
+    LoggerD("Enter");
+
+    const char* old_path = "/opt/usr/media";
+    char replace_path[MAX_PATH_SIZE] = {0, };
+
+    if (strncmp(path, old_path, strlen(old_path)) == 0) {
+        snprintf(replace_path, MAX_PATH_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT),
+                 path + strlen(old_path));
+    } else {
+        snprintf(replace_path, MAX_PATH_SIZE, "%s", path);
+    }
+
+    return std::string(replace_path);
+}
+
 PathPtr Path::create(const std::string& path)
 {
     LoggerD("Enter");
     auto result = std::shared_ptr<Path>(new Path());
-    result->reset(path);
+    result->reset(replaceVirtualRootPath(path.c_str()));
     return result;
 }
 
index c06b9cb..25ec731 100644 (file)
@@ -47,6 +47,7 @@ private:
      * @param path String to verify.
      * @return True when string is a valid path, false otherwise.
      */
+    static std::string replaceVirtualRootPath(const char* path);
     static bool isValid(const std::string& str);
     Path();
     void reset(const std::string& str);