summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2018-08-30 15:50:48 -0400
committerJackLivio <jack@livio.io>2018-08-30 15:50:48 -0400
commitf2af95a3474ab98a1fb6897aee019a45bd12ace5 (patch)
treec6a0a1c4287fb6f242c373a50c01b87bfecd7c80
parentd7213ffb501fbab41078d33cd41de9b0de8f6fc9 (diff)
downloadsdl_core-f2af95a3474ab98a1fb6897aee019a45bd12ace5.tar.gz
Updated based on comments
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc18
-rw-r--r--src/components/utils/src/file_system.cc36
2 files changed, 19 insertions, 35 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc
index a36f396842..e79fb315ce 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc
@@ -200,21 +200,15 @@ void SetAppIconRequest::CopyToIconStorage(
return;
}
-struct compareTime {
- bool operator()(const time_t t1, const time_t t2) {
- double time_difference = difftime(t1, t2);
- if (time_difference > 0) {
- return true;
- } else {
- return false;
- }
- }
-};
-
void SetAppIconRequest::RemoveOldestIcons(const std::string& storage,
const uint32_t icons_amount) const {
const std::vector<std::string> icons_list = file_system::ListFiles(storage);
- std::map<time_t, std::string, compareTime> icon_modification_time;
+ auto compareTime = [](const time_t t1, const time_t t2)
+ -> bool { return difftime(t1, t2) > 0; };
+ std::map<time_t,
+ std::string,
+ std::function<bool(const time_t, const time_t)> >
+ icon_modification_time(compareTime);
std::vector<std::string>::const_iterator it = icons_list.begin();
for (; it != icons_list.end(); ++it) {
const std::string file_name = *it;
diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc
index cb09a3b0b9..8c09e7cfc7 100644
--- a/src/components/utils/src/file_system.cc
+++ b/src/components/utils/src/file_system.cc
@@ -247,21 +247,15 @@ bool file_system::RemoveDirectory(const std::string& directory_name,
return false;
}
error_code ec;
+ bool success;
// If recursive, just force full remove
if (is_recursively) {
- boost::uintmax_t num_removed = fs::remove_all(directory_name, ec);
- if (ec || num_removed == 0) {
- return false;
- }
+ success = (fs::remove_all(directory_name, ec) == 0);
} else {
// Otherwise try to remove
- bool success = fs::remove(directory_name, ec);
- if (!success || ec) {
- return false;
- }
+ success = fs::remove(directory_name, ec);
}
- // Return true on success
- return true;
+ return success && !ec;
}
bool file_system::IsAccessible(const std::string& name, int32_t how) {
@@ -391,19 +385,15 @@ 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 {
- // In case of src and dst on different file systems std::rename returns
- // an error (at least on QNX).
- // Instead, copy the file over and delete the old one
- bool success = CopyFile(src, dst);
- if (!success) {
- return false;
- }
- DeleteFile(src);
-
- return true;
}
- // NOTE this could probably shouldn't be hit if we did it right
+ // In case of src and dst on different file systems std::rename returns
+ // an error (at least on QNX).
+ // Instead, copy the file over and delete the old one
+ bool success = CopyFile(src, dst);
+ if (!success) {
+ return false;
+ }
+ DeleteFile(src);
- return false;
+ return true;
}