From: Andrzej Popowski Date: Fri, 12 Jun 2015 06:49:48 +0000 (+0200) Subject: [Filesystem] - replacing strerror function with GetErrorString and dirname with g_pat... X-Git-Tag: submit/tizen/20150702.103311^2~2^2~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5647e4cbf0716d6b499d93a3641589d7014d6f4;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] - replacing strerror function with GetErrorString and dirname with g_path_get_dirname Change-Id: I4135f770af9f90afabe520c61047c055b8a45be1 Signed-off-by: Andrzej Popowski --- diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index 88594261..1aa87728 100755 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -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); } } diff --git a/src/filesystem/filesystem_stat.cc b/src/filesystem/filesystem_stat.cc index 6dcbfbf1..41d06930 100755 --- a/src/filesystem/filesystem_stat.cc +++ b/src/filesystem/filesystem_stat.cc @@ -21,11 +21,14 @@ #include #include #include +#include #include 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; } } diff --git a/src/filesystem/filesystem_utils.cc b/src/filesystem/filesystem_utils.cc index 1974ae76..c2889350 100755 --- a/src/filesystem/filesystem_utils.cc +++ b/src/filesystem/filesystem_utils.cc @@ -15,6 +15,7 @@ */ #include "filesystem_utils.h" +#include #include #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(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) {