summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Kobziev (GitHub) <43001407+SKobziev@users.noreply.github.com>2019-10-28 20:23:20 +0200
committerJackLivio <jack@livio.io>2019-10-28 14:23:20 -0400
commit50faf6d11c2c3275d957d053013dabbf86ccf9b1 (patch)
tree3f737d4620bfe688047affb245d25b43af6efda0
parentcc0f3e2a4bd0c76b2c3af9a2e8012e7f3152f1f4 (diff)
downloadsdl_core-50faf6d11c2c3275d957d053013dabbf86ccf9b1.tar.gz
Fix/provide operation result to function file system create directory (#2778)
* Provide operation result to function file_system::CreateDirectory The function CreateDirectory signature (return value) was changed in file_system.h * Added const cv for the creating directory path into unit tests(when uses file_system::CreateDirectory) * Fix merge conflict
-rw-r--r--src/components/application_manager/test/help_prompt_manager_test.cc6
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc5
-rw-r--r--src/components/utils/include/utils/file_system.h6
-rw-r--r--src/components/utils/src/file_system.cc10
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) {