[Filesystem] - replacing strerror function with GetErrorString and dirname with g_pat...
authorAndrzej Popowski <a.popowski@samsung.com>
Fri, 12 Jun 2015 06:49:48 +0000 (08:49 +0200)
committerAndrzej Popowski <a.popowski@samsung.com>
Fri, 12 Jun 2015 08:10:17 +0000 (10:10 +0200)
Change-Id: I4135f770af9f90afabe520c61047c055b8a45be1
Signed-off-by: Andrzej Popowski <a.popowski@samsung.com>
src/filesystem/filesystem_manager.cc
src/filesystem/filesystem_stat.cc
src/filesystem/filesystem_utils.cc

index 88594261acb36cd1a7d1145be50a9d0805ba03c3..1aa877282d7f6d53ff43dddca55d074e7a6b3a2e 100755 (executable)
@@ -33,6 +33,7 @@
 #undef _XOPEN_SOURCE
 
 #include "common/logger.h"
+#include "common/tools.h"
 #include "common/scope_exit.h"
 #include "common/extension.h"
 #include "filesystem_file.h"
@@ -40,6 +41,8 @@
 namespace extension {
 namespace filesystem {
 
+using common::tools::GetErrorString;
+
 namespace {
 void storage_cb(int storage_id, storage_state_e state, void* user_data) {
   LoggerD("entered");
@@ -87,12 +90,12 @@ FilesystemError copyDirectory(const std::string& originPath,
   const mode_t create_mode = S_IRWXU | S_IRWXG | S_IRWXO;
   status = mkdir(destPath.c_str(), create_mode);
   if (status) {
-    LoggerE("Cannot create directory: %s", strerror(errno));
+    LoggerE("Cannot create directory: %s", GetErrorString(errno).c_str());
     return FilesystemError::Other;
   }
   DIR* dp = opendir(originPath.c_str());
   if (dp == NULL) {
-    LoggerE("Cannot open directory: %s", strerror(errno));
+    LoggerE("Cannot open directory: %s", GetErrorString(errno).c_str());
     return FilesystemError::Other;
   }
   SCOPE_EXIT {
@@ -160,7 +163,7 @@ FilesystemError perform_deep_copy(const std::string& originPath,
     } else {
       status = remove(destPath.c_str());
       if (status) {
-        LoggerE("Cannot remove old directory: %s", strerror(errno));
+        LoggerE("Cannot remove old directory: %s", GetErrorString(errno).c_str());
         return FilesystemError::Other;
       }
     }
@@ -197,7 +200,7 @@ FilesystemError make_directory_worker(const std::string& path) {
     if (r == 0) {
       return FilesystemError::DirectoryExists;
     }
-    LoggerD("Cannot create directory: %s", strerror(errno));
+    LoggerD("Cannot create directory: %s", GetErrorString(errno).c_str());
     return FilesystemError::Other;
   }
   return parent_result;
@@ -274,13 +277,13 @@ void FilesystemManager::CreateFile(
   status =
       TEMP_FAILURE_RETRY(open(path.c_str(), O_RDWR | O_CREAT, create_mode));
   if (-1 == status) {
-    LoggerE("Cannot create or open file %s: %s", path.c_str(), strerror(errno));
+    LoggerE("Cannot create or open file %s: %s", path.c_str(), GetErrorString(errno).c_str());
     error_cb(FilesystemError::Other);
     return;
   }
   status = close(status);
   if (0 != status) {
-    LoggerE("Cannot close file %s: %s", path.c_str(), strerror(errno));
+    LoggerE("Cannot close file %s: %s", path.c_str(), GetErrorString(errno).c_str());
     error_cb(FilesystemError::Other);
     return;
   }
@@ -317,7 +320,7 @@ void FilesystemManager::Rename(
       error_cb(FilesystemError::Other);
     }
   } else {
-    LoggerE("Cannot rename file: %s", strerror(errno));
+    LoggerE("Cannot rename file: %s", GetErrorString(errno).c_str());
     error_cb(FilesystemError::Other);
   }
 }
index 6dcbfbf10c8cac50437ca1b08ddc32bb11a561f1..41d069308f1c72ca6d8d420e1f25f8b83b4b4a77 100755 (executable)
 #include <unistd.h>
 #include <dirent.h>
 #include <common/logger.h>
+#include <common/tools.h>
 #include <common/scope_exit.h>
 
 namespace extension {
 namespace filesystem {
 
+using common::tools::GetErrorString;
+
 FilesystemStat::FilesystemStat()
     : error(FilesystemError::None),
       valid(false),
@@ -63,7 +66,7 @@ FilesystemStat FilesystemStat::getStat(const std::string& path) {
   LoggerD("enter");
 
   if (0 != stat(path.c_str(), &aStatObj)) {
-    LoggerE("Failed to stat: (%d) %s", errno, strerror(errno));
+    LoggerE("Failed to stat: (%d) %s", errno, GetErrorString(errno).c_str());
     if (ENOENT == errno) {
       _result.error = FilesystemError::NotFound;
     } else {
@@ -93,7 +96,7 @@ FilesystemStat FilesystemStat::getStat(const std::string& path) {
     // Count entries in directory
     DIR* dir = opendir(path.c_str());
     if (!dir) {
-      LoggerE("Cannot open directory: %s", strerror(errno));
+      LoggerE("Cannot open directory: %s", GetErrorString(errno).c_str());
       return _result;
     }
     SCOPE_EXIT {
@@ -113,7 +116,7 @@ FilesystemStat FilesystemStat::getStat(const std::string& path) {
     }
 
     if (status != 0) {
-      LoggerE("Cannot count files in directory: %s", strerror(errno));
+      LoggerE("Cannot count files in directory: %s", GetErrorString(errno).c_str());
       return _result;
     }
   }
index 1974ae76d6d3cfd4c0c27576b5e9181b65ff5482..c28893500e9fe8c5db60246f908348a2a7495aa8 100755 (executable)
@@ -15,6 +15,7 @@
  */
 #include "filesystem_utils.h"
 
+#include <glib.h>
 #include <libgen.h>
 #include "common/logger.h"
 
@@ -34,9 +35,14 @@ std::string get_storage_dir_path(int id, storage_directory_e typeToCheck) {
 }
 
 std::string get_dirname(const std::string& path) {
-  // dirname will modify content: pass a copy
-  std::string buf = path.c_str();
-  return std::string(dirname(const_cast<char*>(buf.c_str())));
+  char* dir = g_path_get_dirname(path.c_str());
+  if (dir) {
+    std::string dir_result(dir);
+    g_free(dir);
+    return dir_result;
+  } else {
+    return std::string(".");
+  }
 }
 
 std::string get_basename(const std::string& path) {