Change uuid file path
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 29 Jan 2021 03:17:06 +0000 (12:17 +0900)
committer장상윤/Tizen Platform Lab(SR)/Engineer/삼성전자 <jeremy.jang@samsung.com>
Fri, 29 Jan 2021 03:27:53 +0000 (12:27 +0900)
It will be stored at {approot}/data/.cion/cion_uuid

Change-Id: I52ef1e62e7afa923c40e9fc8b9f4cfb08245702b
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
cion/common/util/uuid.cc

index 910b788b04255b4e16752dee621cb2635fe8c35f..3bc4ea53e7bfe27be5a236aa7433a71120cb9aa6 100644 (file)
 #include "cion/common/util/uuid.hh"
 
 #include <aul.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include <uuid/uuid.h>
 
 #include <fstream>
 
 namespace {
 
-const char kUuidFileName[] = ".cion_uuid";
+const char kCionDataDir[] = ".cion";
+const char kUuidFilePath[] = ".cion/cion_uuid";
 
 std::string GetAppDataPath() {
   // This API will work only if the caller is an app.
   return aul_get_app_data_path();
 }
 
+bool IsExist(const std::string &path)
+{
+  int fd = open(path.c_str(), O_RDONLY);
+  if (fd < 0)
+    return false;
+  struct stat sb;
+  bool result = (fstat(fd, &sb) == 0);
+  close(fd);
+  return result;
+}
+
+bool CreateDir(const std::string& path) {
+  return (mkdir(path.c_str(), 0700) == 0);
+}
+
 }  // namespace
 
 namespace cion {
@@ -63,7 +83,7 @@ std::string GetUuidPath() {
   if (data_dir.empty())
     return {};
 
-  return data_dir + kUuidFileName;
+  return data_dir + kUuidFilePath;
 }
 
 bool Uuid::GetUUID() {
@@ -71,6 +91,12 @@ bool Uuid::GetUUID() {
   if (data_dir.empty())
     return false;
 
+  std::string cion_dir = data_dir + kCionDataDir;
+  if (!IsExist(cion_dir)) {
+    if (!CreateDir(cion_dir))
+      return false;
+  }
+
   std::ifstream ifs;
   ifs.open(GetUuidPath());
   if (!ifs.is_open())