1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Prevent some spurious delete commands when you have no collection paths

This commit is contained in:
Jeff Mitchell 2011-10-16 17:49:19 -04:00
parent 840460d960
commit fd6235995f
4 changed files with 45 additions and 20 deletions

View File

@ -40,7 +40,8 @@ DatabaseCommand_FileMtimes::execSelect( DatabaseImpl* dbi )
TomahawkSqlQuery query = dbi->newquery();
if( m_prefix.isEmpty() && m_prefixes.isEmpty() )
{
query.exec( "SELECT url, id, mtime FROM file WHERE source IS NULL" );
QString limit( m_checkonly ? QString( " LIMIT 1" ) : QString() );
query.exec( QString( "SELECT url, id, mtime FROM file WHERE source IS NULL%1" ).arg( limit ) );
while( query.next() )
{
QMap< unsigned int, unsigned int > map;

View File

@ -36,13 +36,18 @@ Q_OBJECT
public:
explicit DatabaseCommand_FileMtimes( const QString& prefix = QString(), QObject* parent = 0 )
: DatabaseCommand( parent ), m_prefix( prefix )
: DatabaseCommand( parent ), m_prefix( prefix ), m_checkonly( false )
{}
explicit DatabaseCommand_FileMtimes( const QStringList& prefixes, QObject* parent = 0 )
: DatabaseCommand( parent ), m_prefixes( prefixes )
: DatabaseCommand( parent ), m_prefixes( prefixes ), m_checkonly( false )
{}
//NOTE: when this is called we actually ignore the boolean flag; it's just used to give us the right constructor
explicit DatabaseCommand_FileMtimes( bool /*checkonly*/, QObject* parent = 0 )
: DatabaseCommand( parent ), m_checkonly( true )
{}
virtual void exec( DatabaseImpl* );
virtual bool doesMutates() const { return false; }
virtual QString commandname() const { return "filemtimes"; }
@ -57,6 +62,7 @@ private:
void execSelect( DatabaseImpl* dbi );
QString m_prefix;
QStringList m_prefixes;
bool m_checkonly;
};
#endif // DATABASECOMMAND_FILEMTIMES_H

View File

@ -20,7 +20,6 @@
#include <QThread>
#include <QCoreApplication>
#include <QFileSystemWatcher>
#include <QTimer>
#include "musicscanner.h"
@ -29,7 +28,7 @@
#include "libtomahawk/sourcelist.h"
#include "database/database.h"
#include "database/databasecommand_dirmtimes.h"
#include "database/databasecommand_filemtimes.h"
#include "database/databasecommand_deletefiles.h"
#include "utils/logger.h"
@ -136,17 +135,39 @@ ScanManager::runScan( bool manualFull )
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
return;
if ( !manualFull )
if ( manualFull )
{
runDirScan( TomahawkSettings::instance()->scannerPaths() );
DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() );
connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ),
SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
return;
}
DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() );
connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ),
SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) );
DatabaseCommand_FileMtimes *cmd = new DatabaseCommand_FileMtimes( true );
connect( cmd, SIGNAL( done( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ),
SLOT( fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}
void
ScanManager::fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& mtimes )
{
if ( !mtimes.isEmpty() && TomahawkSettings::instance()->scannerPaths().isEmpty() )
{
DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() );
connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ),
SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
return;
}
runDirScan();
}
@ -156,24 +177,20 @@ ScanManager::filesDeleted( const QStringList& files, const Tomahawk::collection_
Q_UNUSED( files );
Q_UNUSED( collection );
if ( !TomahawkSettings::instance()->scannerPaths().isEmpty() )
runDirScan( TomahawkSettings::instance()->scannerPaths() );
runDirScan();
}
void
ScanManager::runDirScan( const QStringList& paths )
ScanManager::runDirScan()
{
qDebug() << Q_FUNC_INFO;
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
return;
if ( paths.isEmpty() )
{
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ) ) );
return;
}
QStringList paths = TomahawkSettings::instance()->scannerPaths();
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero
{
m_scanTimer->stop();

View File

@ -48,7 +48,7 @@ signals:
public slots:
void runScan( bool manualFull = false );
void runDirScan( const QStringList& paths );
void runDirScan();
private slots:
void scannerFinished();
@ -58,6 +58,7 @@ private slots:
void onSettingsChanged();
void fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& mtimes );
void filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection );
private: