EXPORT_API std::string util::getSystemPath(enum tzplatform_variable id, const std::string& path)
{
- std::string outPath;
-
- {
- ScopeMutex sm(&__pathMutex);
- const char* rawPath = tzplatform_mkpath(id, path.c_str());
- if (rawPath)
- outPath = rawPath;
- else
- _E("Path creation failed");
- }
+ ScopeMutex sm(&__pathMutex);
- return outPath;
+ const char* rawPath = tzplatform_mkpath(id, path.c_str());
+ IF_FAIL_RETURN_TAG(rawPath, EMPTY_STR, _E, "Path creation failed");
+
+ return std::string(rawPath);
}
EXPORT_API std::string util::getUserPath(enum tzplatform_variable id, const std::string& path)
{
IF_FAIL_RETURN_TAG(!util::isSystemUid(uid), EMPTY_STR, _E, "Invalid UID");
+ ScopeMutex sm(&__pathMutex);
+
tzplatform_context* context = NULL;
tzplatform_context_create(&context);
IF_FAIL_RETURN_TAG(context, EMPTY_STR, _E, "tzplatform_context_create() failed");
return EMPTY_STR;
}
- std::string outPath;
+ const char* rawPath = tzplatform_context_mkpath(context, id, path.c_str());
- {
- ScopeMutex sm(&__pathMutex);
- const char* rawPath = tzplatform_context_mkpath(context, id, path.c_str());
- if (rawPath)
- outPath = rawPath;
- else
- _E("Path creation failed");
+ if (!rawPath) {
+ _E("Path creation failed");
+ tzplatform_context_destroy(context);
+ return EMPTY_STR;
}
+ std::string outPath(rawPath);
+
tzplatform_context_destroy(context);
+
return outPath;
}