Commit 618d9059 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Handle invalid folder path

parent c92b010b
......@@ -83,7 +83,16 @@ FolderPtr MediaLibrary::addFolder( const std::string& path )
auto folder = Folder::create( m_dbConnection, path );
if ( folder == nullptr )
return nullptr;
auto dir = fs::createDirectory( path );
std::unique_ptr<fs::IDirectory> dir;
try
{
dir = fs::createDirectory( path );
}
catch ( std::runtime_error& )
{
return nullptr;
}
for ( auto& f : dir->files() )
{
if ( File::create( m_dbConnection, f->fullPath(), folder->id() ) == nullptr )
......
......@@ -71,3 +71,14 @@ TEST_F( Folders, Load )
ASSERT_FALSE( files[0]->isStandAlone() );
ASSERT_FALSE( files[1]->isStandAlone() );
}
TEST_F( Folders, InvalidPath )
{
auto f = ml->addFolder( "/invalid/path" );
ASSERT_EQ( f, nullptr );
auto files = std::vector<FilePtr>{};
bool res = ml->files( files );
ASSERT_TRUE( res );
ASSERT_EQ( files.size(), 0u );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment