From f2af95a3474ab98a1fb6897aee019a45bd12ace5 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Thu, 30 Aug 2018 15:50:48 -0400 Subject: Updated based on comments --- .../src/commands/mobile/set_app_icon_request.cc | 18 ++++------- src/components/utils/src/file_system.cc | 36 ++++++++-------------- 2 files changed, 19 insertions(+), 35 deletions(-) (limited to 'src/components') 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 icons_list = file_system::ListFiles(storage); - std::map icon_modification_time; + auto compareTime = [](const time_t t1, const time_t t2) + -> bool { return difftime(t1, t2) > 0; }; + std::map > + icon_modification_time(compareTime); std::vector::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; } -- cgit v1.2.1