mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 19:58:56 +03:00
FolderMan: Ensure a 1s delay between sync request and start.
That way the propagator can detect files that are still being changed right now and skip them.
This commit is contained in:
parent
292a7357bd
commit
c2ae5e5fd1
2 changed files with 40 additions and 31 deletions
|
@ -428,31 +428,33 @@ void FolderMan::slotScheduleAllFolders()
|
|||
*/
|
||||
void FolderMan::slotScheduleSync( const QString& alias )
|
||||
{
|
||||
if( alias.isEmpty() ) return;
|
||||
|
||||
if( _currentSyncFolder == alias ) {
|
||||
qDebug() << "folder " << alias << " is currently syncing. NOT scheduling.";
|
||||
if( alias.isEmpty() || ! _folderMap.contains(alias) ) {
|
||||
qDebug() << "Not scheduling sync for empty or unknown folder" << alias;
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Schedule folder " << alias << " to sync!";
|
||||
|
||||
if( ! _scheduleQueue.contains(alias ) && _folderMap.contains(alias) ) {
|
||||
if( ! _scheduleQueue.contains(alias) ) {
|
||||
Folder *f = _folderMap[alias];
|
||||
if( f ) {
|
||||
if( !f->syncPaused() ) {
|
||||
f->prepareToSync();
|
||||
} else {
|
||||
qDebug() << "Folder is not enabled, not scheduled!";
|
||||
_socketApi->slotUpdateFolderView(f->alias());
|
||||
return;
|
||||
}
|
||||
if ( !f )
|
||||
return;
|
||||
if( !f->syncPaused() ) {
|
||||
f->prepareToSync();
|
||||
} else {
|
||||
qDebug() << "Folder is not enabled, not scheduled!";
|
||||
_socketApi->slotUpdateFolderView(f->alias());
|
||||
return;
|
||||
}
|
||||
_scheduleQueue.enqueue(alias);
|
||||
} else {
|
||||
qDebug() << " II> Sync for folder " << alias << " already scheduled, do not enqueue!";
|
||||
}
|
||||
// wait a moment until the syncing starts
|
||||
QTimer::singleShot(500, this, SLOT(slotScheduleFolderSync()));
|
||||
|
||||
// Look at the scheduleQueue in a bit to see if the sync is ready to start.
|
||||
// The 1s delay here is essential as the sync will not upload files that were
|
||||
// changed within the last second.
|
||||
QTimer::singleShot(1000, this, SLOT(slotStartScheduledFolderSync()));
|
||||
}
|
||||
|
||||
// only enable or disable foldermans will to schedule and do syncs.
|
||||
|
@ -461,7 +463,7 @@ void FolderMan::setSyncEnabled( bool enabled )
|
|||
{
|
||||
if (!_syncEnabled && enabled && !_scheduleQueue.isEmpty()) {
|
||||
// We have things in our queue that were waiting the the connection to go back on.
|
||||
QTimer::singleShot(200, this, SLOT(slotScheduleFolderSync()));
|
||||
QTimer::singleShot(200, this, SLOT(slotStartScheduledFolderSync()));
|
||||
}
|
||||
_syncEnabled = enabled;
|
||||
// force a redraw in case the network connect status changed
|
||||
|
@ -473,7 +475,7 @@ void FolderMan::setSyncEnabled( bool enabled )
|
|||
* It is either called from the slot where folders enqueue themselves for
|
||||
* syncing or after a folder sync was finished.
|
||||
*/
|
||||
void FolderMan::slotScheduleFolderSync()
|
||||
void FolderMan::slotStartScheduledFolderSync()
|
||||
{
|
||||
if( !_currentSyncFolder.isEmpty() ) {
|
||||
qDebug() << "Currently folder " << _currentSyncFolder << " is running, wait for finish!";
|
||||
|
@ -485,21 +487,26 @@ void FolderMan::slotScheduleFolderSync()
|
|||
return;
|
||||
}
|
||||
|
||||
// Try to start the top scheduled sync.
|
||||
qDebug() << "XX slotScheduleFolderSync: folderQueue size: " << _scheduleQueue.count();
|
||||
if( ! _scheduleQueue.isEmpty() ) {
|
||||
if( !_scheduleQueue.isEmpty() ) {
|
||||
const QString alias = _scheduleQueue.dequeue();
|
||||
if( _folderMap.contains( alias ) ) {
|
||||
Folder *f = _folderMap[alias];
|
||||
if( f && !f->syncPaused() ) {
|
||||
_currentSyncFolder = alias;
|
||||
if( !_folderMap.contains( alias ) ) {
|
||||
qDebug() << "FolderMan: Not syncing queued folder" << alias << ": not in folder map anymore";
|
||||
return;
|
||||
}
|
||||
|
||||
f->startSync( QStringList() );
|
||||
// Start syncing this folder!
|
||||
Folder *f = _folderMap[alias];
|
||||
if( f && !f->syncPaused() ) {
|
||||
_currentSyncFolder = alias;
|
||||
|
||||
// reread the excludes of the socket api
|
||||
// FIXME: the excludes need rework.
|
||||
_socketApi->slotClearExcludesList();
|
||||
_socketApi->slotReadExcludes();
|
||||
}
|
||||
f->startSync( QStringList() );
|
||||
|
||||
// reread the excludes of the socket api
|
||||
// FIXME: the excludes need rework.
|
||||
_socketApi->slotClearExcludesList();
|
||||
_socketApi->slotReadExcludes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +526,7 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
|
|||
|
||||
_currentSyncFolder.clear();
|
||||
|
||||
QTimer::singleShot(200, this, SLOT(slotScheduleFolderSync()));
|
||||
QTimer::singleShot(200, this, SLOT(slotStartScheduledFolderSync()));
|
||||
}
|
||||
|
||||
void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder,
|
||||
|
|
|
@ -134,7 +134,7 @@ public slots:
|
|||
private slots:
|
||||
|
||||
// slot to take the next folder from queue and start syncing.
|
||||
void slotScheduleFolderSync();
|
||||
void slotStartScheduledFolderSync();
|
||||
|
||||
private:
|
||||
// finds all folder configuration files
|
||||
|
@ -153,10 +153,12 @@ private:
|
|||
QSignalMapper *_folderWatcherSignalMapper;
|
||||
QString _currentSyncFolder;
|
||||
bool _syncEnabled;
|
||||
QQueue<QString> _scheduleQueue;
|
||||
QMap<QString, FolderWatcher*> _folderWatchers;
|
||||
QPointer<SocketApi> _socketApi;
|
||||
|
||||
/** The aliases of folders that shall be synced. */
|
||||
QQueue<QString> _scheduleQueue;
|
||||
|
||||
static FolderMan *_instance;
|
||||
explicit FolderMan(QObject *parent = 0);
|
||||
~FolderMan();
|
||||
|
|
Loading…
Reference in a new issue