diff options
4 files changed, 15 insertions, 12 deletions
diff --git a/src/components/application_manager/test/help_prompt_manager_test.cc b/src/components/application_manager/test/help_prompt_manager_test.cc index 1a719012a8..caff56f675 100644 --- a/src/components/application_manager/test/help_prompt_manager_test.cc +++ b/src/components/application_manager/test/help_prompt_manager_test.cc @@ -180,8 +180,10 @@ void HelpPromptManagerTest::SetUp() { mock_help_prompt_manager_ = std::shared_ptr<MockHelpPromptManager>(new MockHelpPromptManager()); - std::string path = file_system::CreateDirectory("storage"); - file_system::CreateFile(path + "/" + "certificate"); + const std::string path("storage"); + if (file_system::CreateDirectory(path)) { + file_system::CreateFile(path + "/" + "certificate"); + } mock_app_ = std::make_shared<application_manager_test::MockApplication>(); } diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 7b5b2dac3b..f99b76b9ad 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -175,8 +175,9 @@ class PolicyHandlerTest : public ::testing::Test { ON_CALL(policy_settings_, enable_policy()).WillByDefault(Return(true)); ON_CALL(app_manager_, event_dispatcher()) .WillByDefault(ReturnRef(mock_event_dispatcher_)); - std::string path = file_system::CreateDirectory("storage"); - file_system::CreateFile(path + "/" + "certificate"); + const std::string path("storage"); + if (file_system::CreateDirectory(path)) + file_system::CreateFile(path + "/" + "certificate"); mock_policy_manager_ = std::make_shared<policy_manager_test::MockPolicyManager>(); ASSERT_TRUE(mock_policy_manager_.use_count() != 0); diff --git a/src/components/utils/include/utils/file_system.h b/src/components/utils/include/utils/file_system.h index f62858417d..9e0dc233af 100644 --- a/src/components/utils/include/utils/file_system.h +++ b/src/components/utils/include/utils/file_system.h @@ -70,10 +70,10 @@ uint64_t FileSize(const std::string& path); /** * @brief Creates directory with owner_all permissions - * @param name path to directory - * @return path to created directory. + * @param path directory to create + * @return true if directory was created or already exist. */ -std::string CreateDirectory(const std::string& name); +bool CreateDirectory(const std::string& path); /** * @brief Creates directory recursively diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index 430cf40da0..c2fb8a4eb4 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -100,16 +100,16 @@ size_t file_system::DirectorySize(const std::string& path) { } // NOTE that boost makes 0777 permissions by default -std::string file_system::CreateDirectory(const std::string& name) { +bool file_system::CreateDirectory(const std::string& path) { error_code ec; - bool success = fs::create_directory(name, ec); + const bool success = fs::create_directory(path, ec); if (!success || ec) { - LOG4CXX_WARN_WITH_ERRNO(logger_, "Unable to create directory: " << name); + LOG4CXX_WARN_WITH_ERRNO(logger_, "Unable to create directory: " << path); } else { // Set 0700 permissions to maintain previous API - fs::permissions(name, fs::perms::owner_all, ec); + fs::permissions(path, fs::perms::owner_all, ec); } - return name; + return success; } bool file_system::CreateDirectoryRecursively(const std::string& path) { |