summaryrefslogtreecommitdiff
path: root/src/components/utils/src/file_system.cc
diff options
context:
space:
mode:
authordtrunov <dtrunov@luxoft.com>2015-09-28 11:59:37 +0300
committerAlexander Kutsan <AKutsan@luxoft.com>2016-01-20 17:55:38 +0200
commit9dbc649a259928feb00350c5df0f28c1875c1d43 (patch)
tree6e002a709d282168bb5cb3602a001c2660b9cc2c /src/components/utils/src/file_system.cc
parent36d96eed2d3f45ba6d8dd07daa6bacd655ebdc7c (diff)
downloadsdl_core-9dbc649a259928feb00350c5df0f28c1875c1d43.tar.gz
Integrate CustomString
Related-issues: APPLINK-12612 Integrate CustomString Integrete CustomString to application, commands, application manager. Related-issues: APPLINK-12612 Fix incorrect convertion of method ConvertPathForURL Related-issues: APPLINK-12612 Fix comments after review Related-issues: APPLINK-12612 Fix comments of review Related-issues: APPLINK-12612 Fix comments after review Related-issues: APPLINK-12612 Fix comments after review. Related-issues: APPLINK-12612 Integrate CustomString to our test. Fixed problem with policy tests after using custom string: Explicitly specified user type "CustomString" in order to use CustomString in PolicyListener Mock Fixed problem with linking "CustomString" to resumption tests. Fixed comment after review in custom_string_test.cc Related-issues: APPLINK-15906 Integrated CustomString to security. Related-issues: APPLINK-12694 Fix comments after review. Related-issues: APPLINK-12694 Fixed comment after review Related-issues: APPLINK-12694 Fixed comments after review Related-issues: APPLINK-15906 Resolve build issues after rebase Fix build with tests
Diffstat (limited to 'src/components/utils/src/file_system.cc')
-rw-r--r--src/components/utils/src/file_system.cc94
1 files changed, 38 insertions, 56 deletions
diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc
index ca17c0f135..91ff0c3b07 100644
--- a/src/components/utils/src/file_system.cc
+++ b/src/components/utils/src/file_system.cc
@@ -49,7 +49,7 @@
CREATE_LOGGERPTR_GLOBAL(logger_, "Utils")
uint64_t file_system::GetAvailableDiskSpace(const std::string& path) {
- struct statvfs fsInfo = { 0 };
+ struct statvfs fsInfo = {0};
if (statvfs(path.c_str(), &fsInfo) == 0) {
return fsInfo.f_bsize * fsInfo.f_bfree;
} else {
@@ -57,9 +57,9 @@ uint64_t file_system::GetAvailableDiskSpace(const std::string& path) {
}
}
-int64_t file_system::FileSize(const std::string &path) {
+int64_t file_system::FileSize(const std::string& path) {
if (file_system::FileExists(path)) {
- struct stat file_info = { 0 };
+ struct stat file_info = {0};
stat(path.c_str(), &file_info);
return file_info.st_size;
}
@@ -75,20 +75,19 @@ size_t file_system::DirectorySize(const std::string& path) {
struct dirent dir_element_;
struct dirent* dir_element = &dir_element_;
#else
- char* direntbuffer =
- new char[offsetof(struct dirent, d_name) +
- pathconf(path.c_str(), _PC_NAME_MAX) + 1];
- struct dirent* dir_element = new(direntbuffer) dirent;
+ char* direntbuffer = new char[offsetof(struct dirent, d_name) +
+ pathconf(path.c_str(), _PC_NAME_MAX) + 1];
+ struct dirent* dir_element = new (direntbuffer) dirent;
#endif
struct dirent* result = NULL;
- struct stat file_info = { 0 };
+ struct stat file_info = {0};
directory = opendir(path.c_str());
if (NULL != directory) {
return_code = readdir_r(directory, dir_element, &result);
for (; NULL != result && 0 == return_code;
return_code = readdir_r(directory, dir_element, &result)) {
- if (0 == strcmp(result->d_name, "..")
- || 0 == strcmp(result->d_name, ".")) {
+ if (0 == strcmp(result->d_name, "..") ||
+ 0 == strcmp(result->d_name, ".")) {
continue;
}
std::string full_element_path = path + "/" + result->d_name;
@@ -132,7 +131,7 @@ bool file_system::CreateDirectoryRecursively(const std::string& path) {
}
bool file_system::IsDirectory(const std::string& name) {
- struct stat status = { 0 };
+ struct stat status = {0};
if (-1 == stat(name.c_str(), &status)) {
return false;
@@ -142,7 +141,7 @@ bool file_system::IsDirectory(const std::string& name) {
}
bool file_system::DirectoryExists(const std::string& name) {
- struct stat status = { 0 };
+ struct stat status = {0};
if (-1 == stat(name.c_str(), &status) || !S_ISDIR(status.st_mode)) {
return false;
@@ -152,7 +151,7 @@ bool file_system::DirectoryExists(const std::string& name) {
}
bool file_system::FileExists(const std::string& name) {
- struct stat status = { 0 };
+ struct stat status = {0};
if (-1 == stat(name.c_str(), &status)) {
return false;
@@ -160,9 +159,9 @@ bool file_system::FileExists(const std::string& name) {
return true;
}
-bool file_system::Write(
- const std::string& file_name, const std::vector<uint8_t>& data,
- std::ios_base::openmode mode) {
+bool file_system::Write(const std::string& file_name,
+ const std::vector<uint8_t>& data,
+ std::ios_base::openmode mode) {
std::ofstream file(file_name.c_str(), std::ios_base::binary | mode);
if (file.is_open()) {
for (uint32_t i = 0; i < data.size(); ++i) {
@@ -176,12 +175,9 @@ bool file_system::Write(
std::ofstream* file_system::Open(const std::string& file_name,
std::ios_base::openmode mode) {
-
-
std::ofstream* file = new std::ofstream();
- file->open( file_name.c_str(),std::ios_base::binary | mode);
+ file->open(file_name.c_str(), std::ios_base::binary | mode);
if (file->is_open()) {
-
return file;
}
@@ -217,7 +213,7 @@ std::string file_system::CurrentWorkingDirectory() {
return std::string(path);
}
-std::string file_system::GetAbsolutePath(const std::string &path) {
+std::string file_system::GetAbsolutePath(const std::string& path) {
char abs_path[PATH_MAX];
if (NULL == realpath(path.c_str(), abs_path)) {
return std::string();
@@ -243,7 +239,7 @@ void file_system::remove_directory_content(const std::string& directory_name) {
char* direntbuffer =
new char[offsetof(struct dirent, d_name) +
pathconf(directory_name.c_str(), _PC_NAME_MAX) + 1];
- struct dirent* dir_element = new(direntbuffer) dirent;
+ struct dirent* dir_element = new (direntbuffer) dirent;
#endif
struct dirent* result = NULL;
@@ -254,8 +250,8 @@ void file_system::remove_directory_content(const std::string& directory_name) {
for (; NULL != result && 0 == return_code;
return_code = readdir_r(directory, dir_element, &result)) {
- if (0 == strcmp(result->d_name, "..")
- || 0 == strcmp(result->d_name, ".")) {
+ if (0 == strcmp(result->d_name, "..") ||
+ 0 == strcmp(result->d_name, ".")) {
continue;
}
@@ -278,8 +274,7 @@ void file_system::remove_directory_content(const std::string& directory_name) {
bool file_system::RemoveDirectory(const std::string& directory_name,
bool is_recursively) {
- if (DirectoryExists(directory_name)
- && IsAccessible(directory_name, W_OK)) {
+ if (DirectoryExists(directory_name) && IsAccessible(directory_name, W_OK)) {
if (is_recursively) {
remove_directory_content(directory_name);
}
@@ -302,7 +297,7 @@ bool file_system::IsReadingAllowed(const std::string& name) {
}
std::vector<std::string> file_system::ListFiles(
- const std::string& directory_name) {
+ const std::string& directory_name) {
std::vector<std::string> listFiles;
if (!DirectoryExists(directory_name)) {
return listFiles;
@@ -317,7 +312,7 @@ std::vector<std::string> file_system::ListFiles(
char* direntbuffer =
new char[offsetof(struct dirent, d_name) +
pathconf(directory_name.c_str(), _PC_NAME_MAX) + 1];
- struct dirent* dir_element = new(direntbuffer) dirent;
+ struct dirent* dir_element = new (direntbuffer) dirent;
#endif
struct dirent* result = NULL;
@@ -327,8 +322,8 @@ std::vector<std::string> file_system::ListFiles(
for (; NULL != result && 0 == return_code;
return_code = readdir_r(directory, dir_element, &result)) {
- if (0 == strcmp(result->d_name, "..")
- || 0 == strcmp(result->d_name, ".")) {
+ if (0 == strcmp(result->d_name, "..") ||
+ 0 == strcmp(result->d_name, ".")) {
continue;
}
@@ -336,7 +331,6 @@ std::vector<std::string> file_system::ListFiles(
}
closedir(directory);
-
}
#ifdef __QNXNTO__
@@ -349,7 +343,7 @@ std::vector<std::string> file_system::ListFiles(
bool file_system::WriteBinaryFile(const std::string& name,
const std::vector<uint8_t>& contents) {
using namespace std;
- ofstream output(name.c_str(), ios_base::binary|ios_base::trunc);
+ ofstream output(name.c_str(), ios_base::binary | ios_base::trunc);
output.write(reinterpret_cast<const char*>(&contents.front()),
contents.size());
return output.good();
@@ -388,29 +382,20 @@ const std::string file_system::ConvertPathForURL(const std::string& path) {
std::string::const_iterator it_path_end = path.end();
const std::string reserved_symbols = "!#$&'()*+,:;=?@[] ";
- std::string::const_iterator it_sym = reserved_symbols.begin();
- std::string::const_iterator it_sym_end = reserved_symbols.end();
-
+ size_t pos = std::string::npos;
std::string converted_path;
- while (it_path != it_path_end) {
- it_sym = reserved_symbols.begin();
- for (; it_sym != it_sym_end; ++it_sym) {
-
- if (*it_path == *it_sym) {
- const size_t size = 100;
- char percent_value[size];
- snprintf(percent_value, size, "%%%x", *it_path);
- converted_path += percent_value;
- ++it_path;
- continue;
- }
+ for (; it_path != it_path_end; ++it_path) {
+ pos = reserved_symbols.find_first_of(*it_path);
+ if (pos != std::string::npos) {
+ const size_t size = 100;
+ char percent_value[size];
+ snprintf(percent_value, size, "%%%x", *it_path);
+ converted_path += percent_value;
+ } else {
+ converted_path += *it_path;
}
-
- converted_path += *it_path;
- ++it_path;
}
-
return converted_path;
}
@@ -424,7 +409,6 @@ bool file_system::CreateFile(const std::string& path) {
}
}
-
uint64_t file_system::GetFileModificationTime(const std::string& path) {
struct stat info;
stat(path.c_str(), &info);
@@ -435,8 +419,7 @@ uint64_t file_system::GetFileModificationTime(const std::string& path) {
#endif
}
-bool file_system::CopyFile(const std::string& src,
- const std::string& dst) {
+bool file_system::CopyFile(const std::string& src, const std::string& dst) {
if (!FileExists(src) || FileExists(dst) || !CreateFile(dst)) {
return false;
}
@@ -448,8 +431,7 @@ bool file_system::CopyFile(const std::string& src,
return true;
}
-bool file_system::MoveFile(const std::string& src,
- const std::string& dst) {
+bool file_system::MoveFile(const std::string& src, const std::string& dst) {
if (std::rename(src.c_str(), dst.c_str()) == 0) {
return true;
} else {