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

File: Force type to be specified when creating a file

parent a62f96a4
......@@ -38,9 +38,9 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_name = sqlite::Traits<std::string>::Load( stmt, 12 );
}
File::File( const fs::IFile* file, unsigned int folderId, const std::string& name )
File::File( const fs::IFile* file, unsigned int folderId, const std::string& name, Type type )
: m_id( 0 )
, m_type( Type::UnknownType )
, m_type( type )
, m_duration( 0 )
, m_albumTrackId( 0 )
, m_playCount( 0 )
......@@ -54,14 +54,14 @@ File::File( const fs::IFile* file, unsigned int folderId, const std::string& nam
{
}
//FIXME: Pass the guessed type and default name
FilePtr File::create( DBConnection dbConnection, const fs::IFile* file, unsigned int folderId )
FilePtr File::create( DBConnection dbConnection, Type type, const fs::IFile* file, unsigned int folderId )
{
auto self = std::make_shared<File>( file, folderId, file->name() );
auto self = std::make_shared<File>( file, folderId, file->name(), type );
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
"(mrl, folder_id, last_modification_date, name) VALUES(?, ?, ?, ?)";
"(type, mrl, folder_id, last_modification_date, name) VALUES(?, ?, ?, ?, ?)";
if ( _Cache::insert( dbConnection, self, req, self->m_mrl, sqlite::ForeignKey( folderId ),
using type_t = std::underlying_type<Type>::type;
if ( _Cache::insert( dbConnection, self, req, static_cast<type_t>( type ), self->m_mrl, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_name ) == false )
return nullptr;
self->m_dbConnection = dbConnection;
......
......@@ -40,9 +40,9 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
// shall be well-formed, and private constructor would prevent that.
// There might be a way with a user-defined allocator, but we'll see that later...
File(DBConnection dbConnection , sqlite3_stmt* stmt);
File(const fs::IFile* file , unsigned int folderId, const std::string &name);
File(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
static FilePtr create(DBConnection dbConnection, const fs::IFile* file , unsigned int folderId);
static FilePtr create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static bool createTable( DBConnection connection );
virtual unsigned int id() const;
......
......@@ -396,13 +396,12 @@ FilePtr MediaLibrary::addFile( const fs::IFile* file, unsigned int folderId )
if ( type == IFile::Type::UnknownType )
return false;
auto fptr = File::create( m_dbConnection, file, folderId );
auto fptr = File::create( m_dbConnection, type, file, folderId );
if ( fptr == nullptr )
{
LOG_ERROR( "Failed to add file ", file->fullPath(), " to the media library" );
return nullptr;
}
fptr->setType( type );
LOG_INFO( "Adding ", file->name() );
m_callback->onFileAdded( fptr );
m_parser->parse( fptr, m_callback );
......
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