mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
Prevent some spurious delete commands when you have no collection paths
This commit is contained in:
@@ -40,7 +40,8 @@ DatabaseCommand_FileMtimes::execSelect( DatabaseImpl* dbi )
|
|||||||
TomahawkSqlQuery query = dbi->newquery();
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
if( m_prefix.isEmpty() && m_prefixes.isEmpty() )
|
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() )
|
while( query.next() )
|
||||||
{
|
{
|
||||||
QMap< unsigned int, unsigned int > map;
|
QMap< unsigned int, unsigned int > map;
|
||||||
|
@@ -36,13 +36,18 @@ Q_OBJECT
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DatabaseCommand_FileMtimes( const QString& prefix = QString(), QObject* parent = 0 )
|
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 )
|
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 void exec( DatabaseImpl* );
|
||||||
virtual bool doesMutates() const { return false; }
|
virtual bool doesMutates() const { return false; }
|
||||||
virtual QString commandname() const { return "filemtimes"; }
|
virtual QString commandname() const { return "filemtimes"; }
|
||||||
@@ -57,6 +62,7 @@ private:
|
|||||||
void execSelect( DatabaseImpl* dbi );
|
void execSelect( DatabaseImpl* dbi );
|
||||||
QString m_prefix;
|
QString m_prefix;
|
||||||
QStringList m_prefixes;
|
QStringList m_prefixes;
|
||||||
|
bool m_checkonly;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASECOMMAND_FILEMTIMES_H
|
#endif // DATABASECOMMAND_FILEMTIMES_H
|
||||||
|
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFileSystemWatcher>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "musicscanner.h"
|
#include "musicscanner.h"
|
||||||
@@ -29,7 +28,7 @@
|
|||||||
#include "libtomahawk/sourcelist.h"
|
#include "libtomahawk/sourcelist.h"
|
||||||
|
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/databasecommand_dirmtimes.h"
|
#include "database/databasecommand_filemtimes.h"
|
||||||
#include "database/databasecommand_deletefiles.h"
|
#include "database/databasecommand_deletefiles.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
@@ -136,17 +135,39 @@ ScanManager::runScan( bool manualFull )
|
|||||||
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseCommand_DeleteFiles *cmd = new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() );
|
DatabaseCommand_FileMtimes *cmd = new DatabaseCommand_FileMtimes( true );
|
||||||
connect( cmd, SIGNAL( done( const QStringList&, const Tomahawk::collection_ptr& ) ),
|
connect( cmd, SIGNAL( done( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ),
|
||||||
SLOT( filesDeleted( const QStringList&, const Tomahawk::collection_ptr& ) ) );
|
SLOT( fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& ) ) );
|
||||||
|
|
||||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
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( files );
|
||||||
Q_UNUSED( collection );
|
Q_UNUSED( collection );
|
||||||
if ( !TomahawkSettings::instance()->scannerPaths().isEmpty() )
|
if ( !TomahawkSettings::instance()->scannerPaths().isEmpty() )
|
||||||
runDirScan( TomahawkSettings::instance()->scannerPaths() );
|
runDirScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScanManager::runDirScan( const QStringList& paths )
|
ScanManager::runDirScan()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( paths.isEmpty() )
|
QStringList paths = TomahawkSettings::instance()->scannerPaths();
|
||||||
{
|
|
||||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ) ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero
|
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero
|
||||||
{
|
{
|
||||||
m_scanTimer->stop();
|
m_scanTimer->stop();
|
||||||
|
@@ -48,7 +48,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void runScan( bool manualFull = false );
|
void runScan( bool manualFull = false );
|
||||||
void runDirScan( const QStringList& paths );
|
void runDirScan();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void scannerFinished();
|
void scannerFinished();
|
||||||
@@ -58,6 +58,7 @@ private slots:
|
|||||||
|
|
||||||
void onSettingsChanged();
|
void onSettingsChanged();
|
||||||
|
|
||||||
|
void fileMtimesCheck( const QMap< QString, QMap< unsigned int, unsigned int > >& mtimes );
|
||||||
void filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection );
|
void filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user