1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

Properly handle order in which mtime update and file delete commands are

run in relation to the rest of scanning
This commit is contained in:
Jeff Mitchell 2011-09-30 18:28:01 -04:00
parent e47b750d21
commit d60b38b3aa
4 changed files with 47 additions and 8 deletions

View File

@ -89,4 +89,5 @@ DatabaseCommand_DirMtimes::execUpdate( DatabaseImpl* dbi )
}
qDebug() << "Saved mtimes for" << m_tosave.size() << "dirs.";
emit done( QMap< QString, unsigned int >() );
}

View File

@ -46,7 +46,7 @@ DirLister::go()
{
if ( m_dirmtimes.contains( dir ) )
{
tDebug( LOGEXTRA ) << "Removing" << dir << "from m_dirmtimes because it's specifically requested";
tDebug( LOGEXTRA ) << "Removing" << dir << "from m_dirmtimes because it's specifically requested (so we want to be sure to scan it)";
m_dirmtimes.remove( dir );
}
@ -63,6 +63,7 @@ DirLister::go()
m_newdirmtimes = m_dirmtimes;
}
tDebug( LOGEXTRA ) << "m_dirmtimes = " << m_dirmtimes;
foreach ( const QString& dir, m_dirs )
{
m_opcount++;
@ -101,10 +102,11 @@ DirLister::scanDir( QDir dir, int depth, DirLister::Mode mode )
if ( m_mode == TomahawkSettings::Dirs && m_dirmtimes.contains( dir.canonicalPath() ) && mtime == m_dirmtimes.value( dir.canonicalPath() ) )
{
// dont scan this dir, unchanged since last time.
tDebug( LOGVERBOSE ) << "Dir unchanged";
}
else
{
tDebug( LOGVERBOSE ) << "Dir changed";
if ( m_mode == TomahawkSettings::Dirs
&& ( m_dirmtimes.contains( dir.canonicalPath() ) || !m_recursive )
&& mtime != m_dirmtimes.value( dir.canonicalPath() ) )
@ -207,7 +209,8 @@ MusicScanner::setDirMtimes( const QMap< QString, unsigned int >& m )
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
return;
}
scan();
else
scan();
}

View File

@ -136,7 +136,39 @@ ScanManager::runScan( bool manualFull )
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
return;
runDirScan( TomahawkSettings::instance()->scannerPaths(), manualFull );
if ( !manualFull )
{
runDirScan( TomahawkSettings::instance()->scannerPaths(), false );
return;
}
DatabaseCommand_DirMtimes *cmd = new DatabaseCommand_DirMtimes( QMap<QString, unsigned int>() );
connect( cmd, SIGNAL( done( QMap< QString, unsigned int > ) ),
SLOT( mtimesDeleted( QMap< QString, unsigned int > ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}
void
ScanManager::mtimesDeleted( QMap< QString, unsigned int > returnedMap )
{
Q_UNUSED( returnedMap );
qDebug() << Q_FUNC_INFO;
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 ) );
}
void
ScanManager::filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection )
{
Q_UNUSED( files );
Q_UNUSED( collection );
runDirScan( TomahawkSettings::instance()->scannerPaths(), true );
}
@ -148,12 +180,11 @@ ScanManager::runDirScan( const QStringList& paths, bool manualFull )
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
return;
if ( paths.isEmpty() || manualFull )
if ( paths.isEmpty() )
{
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( new DatabaseCommand_DirMtimes( QMap<QString, unsigned int>() ) ) );
if ( paths.isEmpty() )
return;
return;
}
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero

View File

@ -19,12 +19,13 @@
#ifndef SCANMANAGER_H
#define SCANMANAGER_H
#include "typedefs.h"
#include <QHash>
#include <QMap>
#include <QObject>
#include <QStringList>
#include <QWeakPointer>
#include <QSet>
class MusicScanner;
@ -57,6 +58,9 @@ private slots:
void onSettingsChanged();
void mtimesDeleted( QMap< QString, unsigned int > returnedMap );
void filesDeleted( const QStringList& files, const Tomahawk::collection_ptr& collection );
private:
static ScanManager* s_instance;