Skip to content

Commit

Permalink
Merge branch 'tickets/DM-39783'
Browse files Browse the repository at this point in the history
  • Loading branch information
iagaponenko committed Jun 24, 2023
2 parents 4e1c41f + 8cac934 commit 62ffa04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/replica/FileUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,22 @@ void FileUtils::verifyFolders(string const& requestorContext, vector<string> con
}
boost::system::error_code ec;
if (createMissingFolders) {
if (!fs::create_directories(path, ec)) {
if (fs::exists(path, ec)) {
bool const isDirectory = fs::is_directory(path, ec);
if (ec.value() != 0) {
throw runtime_error(context + " failed to create folder '" + folder +
"' or its intermediate subfolders, error: " + ec.message());
throw runtime_error(context + " failed to check if the path '" + folder +
"' is a directory, error: " + ec.message());
}
if (!isDirectory) {
throw runtime_error(context + " specified path '" + folder +
"' is not a valid directory");
}
} else {
if (!fs::create_directories(path, ec)) {
if (ec.value() != 0) {
throw runtime_error(context + " failed to create folder '" + folder +
"' or its intermediate subfolders, error: " + ec.message());
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/replica/testFileUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ BOOST_AUTO_TEST_CASE(FileUtils_verifyFolders) {
// Now launch the method to force create the folder.
BOOST_REQUIRE_NO_THROW({ FileUtils::verifyFolders("TEST", folders, createMissingFolders); });

// Repeat the preious operation. It should not fail since the method first checks
// if the path already exists and if it's a valid directory before creating the one.
BOOST_REQUIRE_NO_THROW({ FileUtils::verifyFolders("TEST", folders, createMissingFolders); });

// Make another run w/o attempting creating a folder
BOOST_REQUIRE_NO_THROW({ FileUtils::verifyFolders("TEST", folders, !createMissingFolders); });

Expand Down

0 comments on commit 62ffa04

Please sign in to comment.