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

IFile: Add an isNetwork helper

The migration is assuming network indexing wasn't present before now,
and all existing files are local ones
Fix #48
parent 5685f964
......@@ -67,6 +67,12 @@ public:
/// \brief isExternal returns true if this stream isn't managed by the medialibrary
///
virtual bool isExternal() const = 0;
/**
* @brief isNetwork returns true if this file is on a network location
*
* If the file is external, this is a best guess effort.
*/
virtual bool isNetwork() const = 0;
};
}
......@@ -40,6 +40,7 @@ namespace fs
virtual const std::string& extension() const = 0;
virtual unsigned int lastModificationDate() const = 0;
virtual unsigned int size() const = 0;
virtual bool isNetwork() const = 0;
};
}
......
......@@ -50,6 +50,7 @@ File::File( MediaLibraryPtr ml, sqlite::Row& row )
, m_folderId( row.extract<decltype(m_folderId)>() )
, m_isRemovable( row.extract<decltype(m_isRemovable)>() )
, m_isExternal( row.extract<decltype(m_isExternal)>() )
, m_isNetwork( row.extract<decltype(m_isNetwork)>() )
{
}
......@@ -66,6 +67,7 @@ File::File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, Type type,
, m_folderId( folderId )
, m_isRemovable( isRemovable )
, m_isExternal( false )
, m_isNetwork( file.isNetwork() )
{
assert( ( mediaId == 0 && playlistId != 0 ) || ( mediaId != 0 && playlistId == 0 ) );
}
......@@ -83,6 +85,7 @@ File::File( MediaLibraryPtr ml, int64_t mediaId, int64_t playlistId, IFile::Type
, m_folderId( 0 )
, m_isRemovable( false )
, m_isExternal( true )
, m_isNetwork( utils::file::schemeIs( "file://", mrl ) )
, m_fullPath( mrl )
{
assert( ( mediaId == 0 && playlistId != 0 ) || ( mediaId != 0 && playlistId == 0 ) );
......@@ -164,6 +167,11 @@ bool File::isRemovable() const
return m_isRemovable;
}
bool File::isNetwork() const
{
return m_isNetwork;
}
std::shared_ptr<Media> File::media() const
{
if ( m_mediaId == 0 )
......@@ -212,10 +220,11 @@ std::shared_ptr<File> File::createFromMedia( MediaLibraryPtr ml, int64_t mediaId
auto self = std::make_shared<File>( ml, mediaId, 0, type, fileFs, folderId, isRemovable );
static const std::string req = "INSERT INTO " + File::Table::Name +
"(media_id, mrl, type, folder_id, last_modification_date, size, "
"is_removable, is_external) VALUES(?, ?, ?, ?, ?, ?, ?, 0)";
"is_removable, is_external, is_network) VALUES(?, ?, ?, ?, ?, ?, ?, 0, ?)";
if ( insert( ml, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_size, isRemovable ) == false )
self->m_lastModificationDate, self->m_size, isRemovable,
self->m_isNetwork ) == false )
return nullptr;
self->m_fullPath = fileFs.mrl();
return self;
......@@ -235,10 +244,10 @@ std::shared_ptr<File> File::createFromMedia( MediaLibraryPtr ml, int64_t mediaId
auto self = std::make_shared<File>( ml, mediaId, 0, type, mrl );
static const std::string req = "INSERT INTO " + File::Table::Name +
"(media_id, mrl, type, folder_id, is_removable, is_external) "
"VALUES(?, ?, ?, NULL, 0, 1)";
"(media_id, mrl, type, folder_id, is_removable, is_external, is_network) "
"VALUES(?, ?, ?, NULL, 0, 1, ?)";
if ( insert( ml, self, req, mediaId, mrl, type ) == false )
if ( insert( ml, self, req, mediaId, mrl, type, self->m_isNetwork ) == false )
return nullptr;
return self;
}
......@@ -252,10 +261,11 @@ std::shared_ptr<File> File::createFromPlaylist( MediaLibraryPtr ml, int64_t play
auto self = std::make_shared<File>( ml, 0, playlistId, type , fileFs, folderId, isRemovable );
static const std::string req = "INSERT INTO " + File::Table::Name +
"(playlist_id, mrl, type, folder_id, last_modification_date, size, "
"is_removable, is_external) VALUES(?, ?, ?, ?, ?, ?, ?, 0)";
"is_removable, is_external, is_network) VALUES(?, ?, ?, ?, ?, ?, ?, 0, ?)";
if ( insert( ml, self, req, playlistId, self->m_mrl, type, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_size, isRemovable ) == false )
self->m_lastModificationDate, self->m_size, isRemovable,
self->m_isNetwork ) == false )
return nullptr;
self->m_fullPath = fileFs.mrl();
return self;
......
......@@ -62,6 +62,7 @@ public:
virtual bool isExternal() const override;
bool updateFsInfo( uint32_t newLastModificationDate, uint32_t newSize );
virtual bool isRemovable() const override;
virtual bool isNetwork() const override;
std::shared_ptr<Media> media() const;
bool destroy();
......@@ -116,6 +117,7 @@ private:
const int64_t m_folderId;
const bool m_isRemovable;
const bool m_isExternal;
const bool m_isNetwork;
// Contains the full path as a MRL
mutable std::string m_fullPath;
......
......@@ -210,9 +210,9 @@ IMedia::Type::Unknown ) ),
"INSERT INTO " + File::Table::Name + "("
"id_file, media_id, playlist_id, mrl, type, last_modification_date, size,"
"folder_id, is_removable, is_external) "
"folder_id, is_removable, is_external, is_network) "
"SELECT id_file, media_id, playlist_id, mrl, type, last_modification_date, size,"
"folder_id, is_removable, is_external FROM " + File::Table::Name + "_backup",
"folder_id, is_removable, is_external, 0 FROM " + File::Table::Name + "_backup",
"DROP TABLE " + File::Table::Name + "_backup",
......
......@@ -10,6 +10,7 @@
"folder_id UNSIGNED INTEGER,"
"is_removable BOOLEAN NOT NULL,"
"is_external BOOLEAN NOT NULL,"
"is_network BOOLEAN NOT NULL,"
"FOREIGN KEY (media_id) REFERENCES " + Media::Table::Name
+ "(id_media) ON DELETE CASCADE,"
......
......@@ -55,6 +55,11 @@ const std::string& CommonFile::mrl() const
return m_mrl;
}
bool CommonFile::isNetwork() const
{
return false;
}
}
}
......@@ -37,6 +37,7 @@ public:
virtual const std::string& name() const override;
virtual const std::string& extension() const override;
virtual const std::string& mrl() const override;
virtual bool isNetwork() const override;
protected:
const std::string m_name;
......
......@@ -50,5 +50,10 @@ unsigned int NetworkFile::size() const
return 0;
}
bool NetworkFile::isNetwork() const
{
return true;
}
}
}
......@@ -34,6 +34,7 @@ public:
NetworkFile( const std::string& mrl );
virtual unsigned int lastModificationDate() const override;
virtual unsigned int size() const override;
virtual bool isNetwork() const override;
};
}
}
......@@ -277,6 +277,11 @@ public:
return m_lastModifDate;
}
virtual bool isNetwork() const
{
return false;
}
virtual unsigned int size() const
{
return m_size;
......
......@@ -59,6 +59,11 @@ const std::string& File::mrl() const
return m_mrl;
}
bool File::isNetwork() const
{
return false;
}
unsigned int File::lastModificationDate() const
{
return m_lastModification;
......
......@@ -43,6 +43,7 @@ public:
virtual unsigned int size() const override;
void markAsModified();
virtual const std::string& mrl() const override;
virtual bool isNetwork() const override;
private:
std::string m_name;
......
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