Remove hardcoded path for multiuser support
authorSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Wed, 14 May 2014 13:15:47 +0000 (15:15 +0200)
committerSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Wed, 28 May 2014 10:26:09 +0000 (12:26 +0200)
related to XWALK-1649

common/common.gypi
download/download_context_tizen.cc
filesystem/filesystem_instance.cc
packaging/tizen-extensions-crosswalk.spec
system_info/system_info_storage_tizen.cc
system_info/system_info_utils.cc

index 78b1f3a..beb049a 100644 (file)
       '-fPIC',
       '-fvisibility=hidden',
     ],
+    'variables': {
+      'packages': [
+        'libtzplatform-config',
+      ],
+    },
   },
 }
index 3c42370..1baca29 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <tzplatform_config.h>
 #include <unistd.h>
 
 #include "download/download_context.h"
@@ -31,16 +32,15 @@ const std::string DownloadContext::GetFullDestinationPath(
     const std::string destination) const {
   // TODO(hdq): User should be able to choose store to external storage
   //            i.e. /opt/storage/sdcard/Downloads
-  const std::string directory("/opt/usr/media/");
   const std::string default_folder("Downloads");
   const std::string location = destination.empty() ? default_folder : destination;
-  std::string path = directory + GetActualFolder(location);
+  std::string path = tzplatform_getenv(TZ_USER_CONTENT) + GetActualFolder(location);
 
   // Create path if not exist
   struct stat path_stat;
   if (stat(path.c_str(), &path_stat) == -1
       && mkdir(path.c_str(), 0777) != 0) {
-    path = directory + default_folder;
+    path = tzplatform_getenv(TZ_USER_CONTENT) + default_folder;
   }
 
   return path;
index 1a6355b..236c83b 100644 (file)
@@ -11,6 +11,7 @@
 #include <pkgmgr-info.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <tzplatform_config.h>
 #include <unistd.h>
 
 #include <iostream>
 
 namespace {
 const unsigned kDefaultFileMode = 0755;
-const char kDefaultPath[] = "/opt/usr/media";
-const char kPathCamera[] = "/opt/usr/media/Camera";
-const char kPathSounds[] = "/opt/usr/media/Sounds";
-const char kPathImages[] = "/opt/usr/media/Images";
-const char kPathVideos[] = "/opt/usr/media/Videos";
-const char kPathDownloads[] = "/opt/usr/media/Downloads";
-const char kPathDocuments[] = "/opt/usr/media/Documents";
-const char kPathRingtones[] = "/opt/usr/share/settings/Ringtones";
 
 const char kLocationCamera[] = "camera";
 const char kLocationMusic[] = "music";
@@ -202,13 +195,14 @@ FilesystemInstance::FilesystemInstance() {
     AddInternalStorage(kLocationWgtPrivateTmp, JoinPath(app_path, "tmp"));
   }
 
-  AddInternalStorage(kLocationCamera, kPathCamera);
-  AddInternalStorage(kLocationMusic, kPathSounds);
-  AddInternalStorage(kLocationImages, kPathImages);
-  AddInternalStorage(kLocationVideos, kPathVideos);
-  AddInternalStorage(kLocationDownloads, kPathDownloads);
-  AddInternalStorage(kLocationDocuments, kPathDocuments);
-  AddInternalStorage(kLocationRingtones, kPathRingtones);
+  AddInternalStorage(kLocationCamera, tzplatform_getenv(TZ_USER_CAMERA));
+  AddInternalStorage(kLocationMusic, tzplatform_getenv(TZ_USER_SOUNDS));
+  AddInternalStorage(kLocationImages, tzplatform_getenv(TZ_USER_IMAGES));
+  AddInternalStorage(kLocationVideos, tzplatform_getenv(TZ_USER_VIDEOS));
+  AddInternalStorage(kLocationDownloads, tzplatform_getenv(TZ_USER_DOWNLOADS));
+  AddInternalStorage(kLocationDocuments, tzplatform_getenv(TZ_USER_DOCUMENTS));
+  AddInternalStorage(kLocationRingtones, \
+    tzplatform_mkpath(TZ_USER_SHARE, "settings/Ringtones"));
 }
 
 FilesystemInstance::~FilesystemInstance() {
@@ -223,7 +217,6 @@ FilesystemInstance::~FilesystemInstance() {
 
 void FilesystemInstance::HandleMessage(const char* message) {
   picojson::value v;
-
   std::string err;
   picojson::parse(v, message, message + strlen(message), &err);
   if (!err.empty()) {
@@ -336,7 +329,9 @@ void FilesystemInstance::HandleFileSystemManagerResolve(
   std::string real_path_ack = std::string(real_path_cstr);
   free(real_path_cstr);
 
-  if (check_if_inside_default && real_path_ack.find(kDefaultPath) != 0) {
+  if (check_if_inside_default &&
+      real_path_ack.find(
+          tzplatform_getenv(TZ_USER_CONTENT)) != std::string::npos) {
     PostAsyncErrorReply(msg, INVALID_VALUES_ERR);
     return;
   }
index c42915b..8818ac6 100644 (file)
@@ -1,7 +1,7 @@
 %bcond_with wayland
 
-%define _manifestdir /opt/share/packages
-%define _desktop_icondir /opt/share/icons/default/small
+%define _manifestdir %{TZ_SYS_RW_PACKAGES}
+%define _desktop_icondir %{TZ_SYS_SHARE}/icons/default/small
 %define _bluetooth_demo_package tizen-extensions-crosswalk-bluetooth-demo
 %define _examples_package tizen-extensions-crosswalk-examples
 %define _system_info_demo_package tizen-extensions-crosswalk-system-info-demo
@@ -34,6 +34,7 @@ BuildRequires: pkgconfig(capi-system-power)
 BuildRequires: pkgconfig(capi-system-runtime-info)
 BuildRequires: pkgconfig(capi-system-sensor)
 BuildRequires: pkgconfig(capi-system-system-settings)
+BuildRequires: pkgconfig(libtzplatform-config)
 # For IVI, it doesn't need sim package.
 %if "%{profile}" == "mobile"
 BuildRequires: pkgconfig(capi-telephony-sim)
index 3591ede..680840c 100644 (file)
@@ -5,15 +5,13 @@
 #include "system_info/system_info_storage.h"
 
 #include <sys/statfs.h>
+#include <tzplatform_config.h>
 #include <vconf.h>
 
 #include "common/picojson.h"
 
 namespace {
 
-const char* sStorageInternalPath = "/opt/usr/media";
-const char* sStorageSDCardPath = "/opt/storage/sdcard";
-
 }  // namespace
 
 SysInfoStorage::SysInfoStorage()
@@ -45,7 +43,7 @@ bool SysInfoStorage::Update(picojson::value& error) {
 bool SysInfoStorage::GetInternal(picojson::value& error,
                                  picojson::value& unit) {
   struct statfs fs;
-  if (statfs(sStorageInternalPath, &fs) < 0) {
+  if (statfs(tzplatform_getenv(TZ_USER_CONTENT), &fs) < 0) {
     system_info::SetPicoJsonObjectValue(error, "message",
         picojson::value("Internal Storage path Error"));
     return false;
@@ -79,13 +77,13 @@ bool SysInfoStorage::GetMMC(picojson::value& error, picojson::value& unit) {
   }
 
   struct statfs fs;
-  if (statfs(sStorageInternalPath, &fs) < 0) {
+  if (statfs(tzplatform_getenv(TZ_USER_CONTENT), &fs) < 0) {
     system_info::SetPicoJsonObjectValue(error, "message",
         picojson::value("MMC mount path error"));
     return false;
   }
 
-  statfs(sStorageSDCardPath, &fs);
+  statfs(tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard"), &fs);
   double available_capacity = static_cast<double>(fs.f_bsize) *
                               static_cast<double>(fs.f_bavail);
   double capacity = static_cast<double>(fs.f_bsize) *
index ef49f9e..d471cfa 100644 (file)
@@ -5,6 +5,7 @@
 #include "system_info/system_info_utils.h"
 
 #include <stdio.h>
+#include <tzplatform_config.h>
 #include <unistd.h>
 
 #include <algorithm>
@@ -24,7 +25,7 @@ char* GetDuidProperty() {
   FILE *fp = NULL;
   static char duid[kDuid_buffer_size] = {0, };
   size_t len = strlen(kDuid_str_key);
-  fp = fopen("/opt/usr/etc/system_info_cache.ini", "r");
+  fp = fopen(tzplatform_mkpath(TZ_USER_ETC, "system_info_cache.ini"), "r");
 
   if (fp) {
     while (fgets(duid, kDuid_buffer_size - 1, fp)) {