Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions Sofa/framework/Helper/src/sofa/helper/system/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,30 @@ bool FileSystem::createDirectory(const std::string& path)
return true;
}
#else
if (mkdir(path.c_str(), 0755))
int status = mkdir(path.c_str(), 0755);
if(status)
{
msg_error(error) << path << ": " << strerror(errno);
return true;
if (errno != EEXIST)
{
msg_error(error) << path << ": " << strerror(errno);
return true;
}
else
{
struct stat st_buf;
if (stat(path.c_str(), &st_buf) == 0)
{
if ((st_buf.st_mode & S_IFMT) != S_IFDIR) {
msg_error(error) << path << ": File exists and is not a directoy";
return true;
}
else
{
return false;
}
}

}
}
#endif
else
Expand Down
22 changes: 10 additions & 12 deletions Sofa/framework/Helper/test/system/FileSystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,16 @@ TEST(FileSystemTest, createDirectory_alreadyExists)
// required to be able to use EXPECT_MSG_NOEMIT and EXPECT_MSG_EMIT
sofa::helper::logging::MessageDispatcher::addHandler(sofa::testing::MainGtestMessageHandler::getInstance() ) ;

{
EXPECT_MSG_NOEMIT(Error) ;
FileSystem::createDirectory("createDirectoryTestDir");
}
{
EXPECT_MSG_EMIT(Error) ;
EXPECT_TRUE(FileSystem::createDirectory("createDirectoryTestDir"));
}
{
EXPECT_MSG_NOEMIT(Error) ;
FileSystem::removeDirectory("createDirectoryTestDir");
}
EXPECT_MSG_NOEMIT(Error) ;

EXPECT_FALSE(FileSystem::createDirectory("createDirectoryTestDir"));
EXPECT_TRUE(FileSystem::exists("createDirectoryTestDir"));
EXPECT_TRUE(FileSystem::isDirectory("createDirectoryTestDir"));
EXPECT_FALSE(FileSystem::createDirectory("createDirectoryTestDir"));

// Cleanup
FileSystem::removeDirectory("createDirectoryTestDir");

}

TEST(FileSystemTest, removeDirectory)
Expand Down