Commit bb107c80 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

factory: FileSystem: Don't let createDirectory throw exceptions

parent c7cf425c
......@@ -56,16 +56,7 @@ bool FsDiscoverer::discover( const std::string &entryPoint )
return true;
}
// Otherwise, create a directory, and check it for modifications
std::shared_ptr<fs::IDirectory> fsDir;
try
{
fsDir = m_fsFactory->createDirectory( entryPoint );
}
catch (std::exception& ex)
{
LOG_ERROR("Failed to create an IDirectory for ", entryPoint, ": ", ex.what());
return false;
}
std::shared_ptr<fs::IDirectory> fsDir = m_fsFactory->createDirectory( entryPoint );
if ( fsDir == nullptr )
{
LOG_ERROR("Failed to create an IDirectory for ", entryPoint );
......@@ -89,6 +80,12 @@ void FsDiscoverer::reload()
for ( const auto& f : rootFolders )
{
auto folder = m_fsFactory->createDirectory( f->path() );
if ( folder == nullptr )
{
LOG_INFO( "Removing folder ", f->path() );
m_ml->deleteFolder( f );
continue;
}
if ( folder->lastModificationDate() == f->lastModificationDate() )
{
LOG_INFO( f->path(), " isn't modified" );
......@@ -137,6 +134,8 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, Folder* parentFolder
for ( const auto& subFolderPath : folder->dirs() )
{
auto subFolder = m_fsFactory->createDirectory( subFolderPath );
if ( subFolder == nullptr )
continue;
auto it = std::find_if( begin( subFoldersInDB ), end( subFoldersInDB ), [subFolderPath](const std::shared_ptr<IFolder>& f) {
return f->path() == subFolderPath;
......
......@@ -23,6 +23,7 @@
#include "factory/FileSystem.h"
#include "filesystem/IDirectory.h"
#include "filesystem/IFile.h"
#include "logging/Logger.h"
#if defined(__linux__) || defined(__APPLE__)
# include "filesystem/unix/Directory.h"
......@@ -44,9 +45,17 @@ std::shared_ptr<fs::IDirectory> FileSystemFactory::createDirectory( const std::s
const auto it = m_dirs.find( path );
if ( it != end( m_dirs ) )
return it->second;
auto dir = std::make_shared<fs::Directory>( path );
m_dirs[path] = dir;
return dir;
try
{
auto dir = std::make_shared<fs::Directory>( path );
m_dirs[path] = dir;
return dir;
}
catch(std::exception& ex)
{
LOG_ERROR( "Failed to create fs::IDirectory for ", path, ": ", ex.what());
return nullptr;
}
}
std::unique_ptr<fs::IFile> FileSystemFactory::createFile(const std::string& fileName)
......
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