get external path using storage api. 59/80759/7
authorjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 20 Jul 2016 04:55:10 +0000 (13:55 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 9 Aug 2016 06:33:59 +0000 (23:33 -0700)
Change-Id: Idac5f15520125462240bc2fdc31e98d6505eeb7b
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
CMakeLists.txt
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/paths.cc
src/common/paths.h

index cecf805..39d2f1d 100644 (file)
@@ -60,6 +60,7 @@ PKG_CHECK_MODULES(GUM_DEPS REQUIRED libgum)
 PKG_CHECK_MODULES(APP2SD_DEPS REQUIRED app2sd)
 PKG_CHECK_MODULES(CAPI_SYSTEM_INFO_DEPS REQUIRED capi-system-info)
 PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf vconf-internal-keys)
+PKG_CHECK_MODULES(STORAGE_DEPS REQUIRED storage)
 
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options)
 FIND_PACKAGE(GTest REQUIRED)
index 5a236e4..b2cb7f5 100644 (file)
@@ -39,6 +39,7 @@ BuildRequires:  pkgconfig(app2sd)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
+BuildRequires:  pkgconfig(storage)
 
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
index 92506d9..15288ab 100644 (file)
@@ -120,6 +120,7 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC
   GUM_DEPS
   APP2SD_DEPS
   CAPI_SYSTEM_INFO_DEPS
+  STORAGE_DEPS
   Boost
 )
 
index e971c86..aa9720f 100644 (file)
@@ -4,8 +4,11 @@
 
 #include "common/paths.h"
 
+#include <manifest_parser/utils/logging.h>
+
 #include <pwd.h>
 #include <tzplatform_config.h>
+#include <storage-internal.h>
 
 namespace bf = boost::filesystem;
 
@@ -14,7 +17,27 @@ namespace {
 const int32_t kPWBufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
 const char kImageDir[] = ".image";
 const char kBckExtension[] = ".bck";
-const char kExternalStorageDirPrefix[] = "SDCardA1";
+
+std::string GetSDcardMountPath() {
+  char* sdpath = nullptr;
+  int storage_id = 0;
+  int ret;
+
+  ret = storage_get_primary_sdcard(&storage_id, &sdpath);
+  if (ret != STORAGE_ERROR_NONE) {
+    if (sdpath)
+      free(sdpath);
+    return {};
+  }
+
+  if (sdpath) {
+    std::string mount_path(sdpath);
+    free(sdpath);
+    return mount_path;
+  }
+
+  return {};
+}
 
 boost::filesystem::path GetBackupPath(
     const boost::filesystem::path& pkg_path) {
@@ -71,12 +94,16 @@ boost::filesystem::path GetZipPackageLocation(
 }
 
 boost::filesystem::path GetExternalCardPath() {
-  return bf::path(tzplatform_mkpath(TZ_SYS_MEDIA, kExternalStorageDirPrefix));
+  return bf::path(GetSDcardMountPath());
 }
 
 boost::filesystem::path GetExternalTepPath(RequestMode request_mode,
                                            uid_t uid) {
-  bf::path result = GetExternalCardPath() / "tep";
+  bf::path result;
+  bf::path ext_mount_path = GetExternalCardPath();
+  if (bf::is_empty(ext_mount_path))
+    return result;
+  result = ext_mount_path / "tep";
   if (request_mode == RequestMode::USER)
     result /= GetUserNameForUID(uid);
   return result;
index 1592155..4f6edab 100644 (file)
@@ -6,6 +6,7 @@
 #define COMMON_PATHS_H_
 
 #include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
 #include <unistd.h>
 
 #include <string>