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

MediaLibrary: Recursively create thumbnail directory

parent c98c3698
......@@ -250,6 +250,38 @@ bool MediaLibrary::validateSearchPattern( const std::string& pattern )
return pattern.size() >= 3;
}
bool MediaLibrary::createThumbnailFolder( const std::string& thumbnailPath ) const
{
auto paths = utils::file::splitPath( thumbnailPath, true );
#ifndef _WIN32
std::string fullPath{ "/" };
#else
std::string fullPath;
#endif
while ( paths.empty() == false )
{
fullPath += paths.top();
LOG_ERROR( "Creating path: ", fullPath );
#ifdef _WIN32
if ( mkdir( fullPath.c_str() ) != 0 )
#else
if ( mkdir( fullPath.c_str(), S_IRWXU ) != 0 )
#endif
{
if ( errno != EEXIST )
return false;
}
paths.pop();
#ifndef _WIN32
fullPath += "/";
#else
fullPath += "\\";
#endif
}
return true;
}
InitializeResult MediaLibrary::initialize( const std::string& dbPath,
const std::string& thumbnailPath,
IMediaLibraryCb* mlCallback )
......@@ -270,18 +302,11 @@ InitializeResult MediaLibrary::initialize( const std::string& dbPath,
}
}
addLocalFsFactory();
#ifdef _WIN32
if ( mkdir( thumbnailPath.c_str() ) != 0 )
#else
if ( mkdir( thumbnailPath.c_str(), S_IRWXU ) != 0 )
#endif
if ( createThumbnailFolder( thumbnailPath ) == false )
{
if ( errno != EEXIST )
{
LOG_ERROR( "Failed to create thumbnail directory (", thumbnailPath,
": ", strerror( errno ) );
return InitializeResult::Failed;
}
LOG_ERROR( "Failed to create thumbnail directory (", thumbnailPath,
": ", strerror( errno ) );
return InitializeResult::Failed;
}
m_thumbnailPath = thumbnailPath;
m_callback = mlCallback;
......
......@@ -202,6 +202,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
static bool validateSearchPattern( const std::string& pattern );
// Returns true if the device actually changed
bool onDeviceChanged( fs::IFileSystemFactory& fsFactory, Device& device );
bool createThumbnailFolder( const std::string& thumbnailPath ) const;
protected:
virtual void addLocalFsFactory();
......
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