From e8424ddb04aec53503e829181ad88b82218bfdc7 Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Fri, 23 Sep 2016 12:25:02 +0200 Subject: [PATCH] [Archive] Replace old virtual root path. [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 --- src/archive/filesystem_path.cc | 22 +++++++++++++++++++++- src/archive/filesystem_path.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/archive/filesystem_path.cc b/src/archive/filesystem_path.cc index 1357a71..0b9a902 100755 --- a/src/archive/filesystem_path.cc +++ b/src/archive/filesystem_path.cc @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "filesystem_path.h" #include "common/logger.h" @@ -26,13 +28,31 @@ 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(new Path()); - result->reset(path); + result->reset(replaceVirtualRootPath(path.c_str())); return result; } diff --git a/src/archive/filesystem_path.h b/src/archive/filesystem_path.h index c06b9cb..25ec731 100644 --- a/src/archive/filesystem_path.h +++ b/src/archive/filesystem_path.h @@ -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); -- 2.7.4