diff --git a/include/rcpputils/filesystem_helper.hpp b/include/rcpputils/filesystem_helper.hpp index 507fdba9..93fa580d 100644 --- a/include/rcpputils/filesystem_helper.hpp +++ b/include/rcpputils/filesystem_helper.hpp @@ -511,7 +511,7 @@ inline bool create_directories(const path & p) #endif } } - return status == 0; + return status == 0 && p_built.is_directory(); } /** diff --git a/test/test_filesystem_helper.cpp b/test/test_filesystem_helper.cpp index 11952d66..a83047f0 100644 --- a/test/test_filesystem_helper.cpp +++ b/test/test_filesystem_helper.cpp @@ -286,6 +286,7 @@ TEST(TestFilesystemHelper, filesystem_manipulation) EXPECT_TRUE(rcpputils::fs::exists(file)); EXPECT_TRUE(rcpputils::fs::is_regular_file(file)); EXPECT_FALSE(rcpputils::fs::is_directory(file)); + EXPECT_FALSE(rcpputils::fs::create_directories(file)); EXPECT_GE(rcpputils::fs::file_size(file), expected_file_size); EXPECT_THROW(rcpputils::fs::file_size(dir), std::system_error) << "file_size is only applicable for files!"; @@ -352,6 +353,9 @@ TEST(TestFilesystemHelper, filesystem_manipulation) ASSERT_FALSE(rcpputils::fs::exists(file)); } ASSERT_FALSE(rcpputils::fs::exists(dir)); + + // Empty path/directory cannot be created + EXPECT_FALSE(rcpputils::fs::create_directories(rcpputils::fs::path(""))); } TEST(TestFilesystemHelper, remove_extension)