#undef _XOPEN_SOURCE
#include "common/logger.h"
+#include "common/tools.h"
#include "common/scope_exit.h"
#include "common/extension.h"
#include "filesystem_file.h"
namespace extension {
namespace filesystem {
+using common::tools::GetErrorString;
+
namespace {
void storage_cb(int storage_id, storage_state_e state, void* user_data) {
LoggerD("entered");
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 {
} 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;
}
}
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;
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;
}
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);
}
}
#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),
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 {
// 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 {
}
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;
}
}
*/
#include "filesystem_utils.h"
+#include <glib.h>
#include <libgen.h>
#include "common/logger.h"
}
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) {