The method uses aul API to get the data path.
If it's failed, the method tries to get the data path using
tzplatform_config() API.
Change-Id: I63168e61ed3f7b8f5b206393ab6890c9b3949034
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
INCLUDE(FindPkgConfig)
INCLUDE(ApplyPkgConfig)
+PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul)
PKG_CHECK_MODULES(CAPI_APPFW_APP_COMMON_DEPS REQUIRED capi-appfw-app-common)
PKG_CHECK_MODULES(CAPI_BASE_COMMON_DEPS REQUIRED capi-base-common)
PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(aul)
%if 0%{?gcov:1}
BuildRequires: lcov
${CMAKE_CURRENT_SOURCE_DIR}/../include/)
APPLY_PKG_CONFIG(${TARGET_PREFERENCE} PUBLIC
+ AUL_DEPS
CAPI_APPFW_APP_COMMON_DEPS
CAPI_BASE_COMMON_DEPS
DLOG_DEPS
GLIB_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
)
INSTALL(TARGETS ${TARGET_PREFERENCE}
return false;
}
-void File::CreateDir() {
+bool File::CreateDir() {
std::string pref_dir = Path::Get();
+ if (pref_dir.empty()) return false;
+
if (access(pref_dir.c_str(), F_OK) != 0) {
mode_t dir_mode = 0664 | 0111;
- if (mkdir(pref_dir.c_str(), dir_mode) != 0)
+ if (mkdir(pref_dir.c_str(), dir_mode) != 0) {
+ if (errno == EEXIST) return true;
_E("mkdir() is failed. path(%s), errno(%d)", pref_dir.c_str(), errno);
+ return false;
+ }
}
+
+ return true;
}
int File::Open(bool readonly) {
int File::TryWrite() {
int ret = Open(false);
if (ret < 0) {
- if (ret == -ENOENT)
- CreateDir();
+ if (ret == -ENOENT) {
+ if (!CreateDir())
+ _E("Failed to create directory");
+ }
return static_cast<int>(Error::ERROR_FILE_OPEN);
}
#include <list>
#include <memory>
#include <string>
+#include <vector>
#include "preference/data-internal.hh"
ERROR_FILE_LOCK = -26,
};
- File(std::string name, bool is_checksum = false);
+ explicit File(std::string name, bool is_checksum = false);
File(std::string name, std::string pref_path, bool is_checksum = false);
~File();
void Close();
private:
- void CreateDir();
+ bool CreateDir();
int Open(bool readonly = true);
int Sync();
bool Lock(bool readonly = true);
* limitations under the License.
*/
-#include <app_common.h>
+#include "preference/path-internal.hh"
+
+#include <aul.h>
#include <sys/types.h>
+#include <tzplatform_config.h>
#include <unistd.h>
#include <mutex>
#include "preference/log-internal.hh"
-#include "preference/path-internal.hh"
namespace preference {
namespace internal {
std::string Path::Get() {
- static std::mutex mtx;
+ static std::mutex mutex;
static std::string path;
if (!path.empty())
return path;
- std::lock_guard<std::mutex> lock(mtx);
- char* data_path = app_get_data_path();
- if (data_path != nullptr) {
- path = std::string(data_path) + ".pref/";
- free(data_path);
+ std::lock_guard<std::mutex> lock(mutex);
+ const char* data_path = aul_get_app_data_path();
+ if (data_path == nullptr) {
+ _E("Failed to get data path. uid(%u)", getuid());
+ if (getuid() < 5000) {
+ path = "/tmp/." + std::to_string(getpid()) + "_pref/";
+ } else {
+ char pkgid[256] = { 0, };
+ if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) != AUL_R_OK) {
+ _E("Failed to get pkgid by pid(%d)", getpid());
+ return path;
+ }
+
+ path = std::string(tzplatform_getenv(TZ_USER_APP)) + "/" +
+ std::string(pkgid) + "/data/.pref/";
+ }
} else {
- path = "/tmp/." + std::to_string(getpid()) + "_pref/";
+ path = std::string(data_path) + ".pref/";
}
return path;