2012-02-17 12:48:31 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
2012-07-20 19:13:23 +04:00
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderman.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folder.h"
|
|
|
|
#include "syncresult.h"
|
|
|
|
#include "theme.h"
|
2014-07-17 13:31:45 +04:00
|
|
|
#include "socketapi.h"
|
2014-08-29 22:40:33 +04:00
|
|
|
#include "account.h"
|
2014-12-18 14:09:48 +03:00
|
|
|
#include "accountstate.h"
|
2015-04-09 17:19:17 +03:00
|
|
|
#include "accountmanager.h"
|
2015-03-11 12:51:36 +03:00
|
|
|
#include "filesystem.h"
|
2016-04-29 17:14:18 +03:00
|
|
|
#include "lockwatcher.h"
|
2017-09-01 19:11:43 +03:00
|
|
|
#include "common/asserts.h"
|
2015-11-20 17:14:22 +03:00
|
|
|
#include <syncengine.h>
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-10-20 20:47:33 +04:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#endif
|
2012-12-07 22:53:36 +04:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <shlobj.h>
|
|
|
|
#endif
|
2012-10-20 20:47:33 +04:00
|
|
|
|
2013-06-06 19:59:50 +04:00
|
|
|
#include <QMessageBox>
|
2012-05-21 18:48:49 +04:00
|
|
|
#include <QtCore>
|
2014-12-03 00:32:54 +03:00
|
|
|
#include <QMutableSetIterator>
|
|
|
|
#include <QSet>
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcFolderMan, "gui.folder.manager", QtInfoMsg)
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
FolderMan *FolderMan::_instance = 0;
|
|
|
|
|
|
|
|
FolderMan::FolderMan(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, _currentSyncFolder(0)
|
|
|
|
, _syncEnabled(true)
|
|
|
|
, _lockWatcher(new LockWatcher)
|
2017-10-04 14:49:42 +03:00
|
|
|
, _navigationPaneHelper(this)
|
2017-05-17 11:55:42 +03:00
|
|
|
, _appRestartRequired(false)
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2017-02-07 15:52:15 +03:00
|
|
|
ASSERT(!_instance);
|
2014-05-26 16:34:08 +04:00
|
|
|
_instance = this;
|
2014-07-15 15:34:32 +04:00
|
|
|
|
2016-03-18 20:31:01 +03:00
|
|
|
_socketApi.reset(new SocketApi);
|
2014-12-03 00:32:54 +03:00
|
|
|
|
2014-12-10 15:01:36 +03:00
|
|
|
ConfigFile cfg;
|
2014-12-03 00:32:54 +03:00
|
|
|
int polltime = cfg.remotePollInterval();
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "setting remote poll timer interval to" << polltime << "msec";
|
2017-05-17 11:55:42 +03:00
|
|
|
_etagPollTimer.setInterval(polltime);
|
2017-09-20 11:14:48 +03:00
|
|
|
QObject::connect(&_etagPollTimer, &QTimer::timeout, this, &FolderMan::slotEtagPollTimerTimeout);
|
2014-12-03 00:32:54 +03:00
|
|
|
_etagPollTimer.start();
|
2014-12-18 14:09:48 +03:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
_startScheduledSyncTimer.setSingleShot(true);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(&_startScheduledSyncTimer, &QTimer::timeout,
|
|
|
|
this, &FolderMan::slotStartScheduledFolderSync);
|
2015-01-16 14:23:15 +03:00
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
_timeScheduler.setInterval(5000);
|
|
|
|
_timeScheduler.setSingleShot(false);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(&_timeScheduler, &QTimer::timeout,
|
|
|
|
this, &FolderMan::slotScheduleFolderByTime);
|
2016-10-18 17:04:25 +03:00
|
|
|
_timeScheduler.start();
|
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(AccountManager::instance(), &AccountManager::accountRemoved,
|
|
|
|
this, &FolderMan::slotRemoveFoldersForAccount);
|
2016-04-29 17:14:18 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_lockWatcher.data(), &LockWatcher::fileUnlocked,
|
|
|
|
this, &FolderMan::slotWatchedFileUnlocked);
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2013-07-22 15:59:52 +04:00
|
|
|
FolderMan *FolderMan::instance()
|
|
|
|
{
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
FolderMan::~FolderMan()
|
|
|
|
{
|
2013-06-29 00:27:53 +04:00
|
|
|
qDeleteAll(_folderMap);
|
2014-05-26 16:34:08 +04:00
|
|
|
_instance = 0;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
OCC::Folder::Map FolderMan::map()
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
|
|
|
return _folderMap;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::unloadFolder(Folder *f)
|
2014-07-15 18:06:06 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!f) {
|
2015-02-27 12:42:59 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-07-25 14:20:38 +04:00
|
|
|
|
2016-03-18 20:31:01 +03:00
|
|
|
_socketApi->slotUnregisterPath(f->alias());
|
2015-02-27 12:42:59 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
_folderMap.remove(f->alias());
|
2015-06-17 16:55:48 +03:00
|
|
|
|
2017-09-20 11:14:48 +03:00
|
|
|
disconnect(f, &Folder::syncStarted,
|
|
|
|
this, &FolderMan::slotFolderSyncStarted);
|
|
|
|
disconnect(f, &Folder::syncFinished,
|
|
|
|
this, &FolderMan::slotFolderSyncFinished);
|
|
|
|
disconnect(f, &Folder::syncStateChange,
|
|
|
|
this, &FolderMan::slotForwardFolderSyncStateChange);
|
|
|
|
disconnect(f, &Folder::syncPausedChanged,
|
|
|
|
this, &FolderMan::slotFolderSyncPaused);
|
2017-09-20 12:48:13 +03:00
|
|
|
disconnect(&f->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
|
|
|
|
_socketApi.data(), &SocketApi::broadcastStatusPushMessage);
|
2017-09-20 11:14:48 +03:00
|
|
|
disconnect(f, &Folder::watchedFileChangedExternally,
|
|
|
|
&f->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::slotPathTouched);
|
2014-07-15 18:06:06 +04:00
|
|
|
}
|
|
|
|
|
2015-02-27 12:42:59 +03:00
|
|
|
int FolderMan::unloadAndDeleteAllFolders()
|
2013-06-03 19:26:48 +04:00
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
// clear the list of existing folders.
|
|
|
|
Folder::MapIterator i(_folderMap);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *f = i.value();
|
2015-04-28 16:13:39 +03:00
|
|
|
unloadFolder(f);
|
2015-02-27 12:42:59 +03:00
|
|
|
delete f;
|
2013-06-03 19:26:48 +04:00
|
|
|
cnt++;
|
|
|
|
}
|
2017-02-07 15:52:15 +03:00
|
|
|
ASSERT(_folderMap.isEmpty());
|
|
|
|
|
2015-04-28 16:13:39 +03:00
|
|
|
_lastSyncFolder = 0;
|
|
|
|
_currentSyncFolder = 0;
|
2016-10-18 17:04:25 +03:00
|
|
|
_scheduledFolders.clear();
|
2017-07-06 15:02:21 +03:00
|
|
|
emit folderListChanged(_folderMap);
|
2015-09-04 11:33:48 +03:00
|
|
|
emit scheduleQueueChanged();
|
2014-07-15 18:06:06 +04:00
|
|
|
|
2013-06-03 19:26:48 +04:00
|
|
|
return cnt;
|
|
|
|
}
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2017-10-09 13:06:11 +03:00
|
|
|
void FolderMan::registerFolderWithSocketApi(Folder *folder)
|
2014-01-11 23:35:16 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!folder)
|
|
|
|
return;
|
|
|
|
if (!QDir(folder->path()).exists())
|
|
|
|
return;
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2014-07-25 14:20:38 +04:00
|
|
|
// register the folder with the socket API
|
2016-04-28 23:43:53 +03:00
|
|
|
if (folder->canSync())
|
|
|
|
_socketApi->slotRegisterPath(folder->alias());
|
2014-01-11 23:35:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 12:35:18 +04:00
|
|
|
int FolderMan::setupFolders()
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2015-04-24 11:18:33 +03:00
|
|
|
unloadAndDeleteAllFolders();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2017-08-16 09:36:52 +03:00
|
|
|
auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));
|
2015-04-24 11:18:33 +03:00
|
|
|
const auto accountsWithSettings = settings->childGroups();
|
|
|
|
if (accountsWithSettings.isEmpty()) {
|
2015-07-31 19:31:54 +03:00
|
|
|
int r = setupFoldersMigration();
|
|
|
|
if (r > 0) {
|
2015-08-06 13:49:18 +03:00
|
|
|
AccountManager::instance()->save(false); // don't save credentials, they had not been loaded from keychain
|
2015-07-31 19:31:54 +03:00
|
|
|
}
|
|
|
|
return r;
|
2015-04-24 11:18:33 +03:00
|
|
|
}
|
2013-02-10 14:00:22 +04:00
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Setup folders from settings file";
|
2014-05-26 16:34:08 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (const auto &account, AccountManager::instance()->accounts()) {
|
2015-04-24 11:18:33 +03:00
|
|
|
const auto id = account->account()->id();
|
|
|
|
if (!accountsWithSettings.contains(id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
settings->beginGroup(id);
|
2016-11-22 17:30:12 +03:00
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
settings->beginGroup(QLatin1String("Folders"));
|
2016-11-22 17:30:12 +03:00
|
|
|
setupFoldersHelper(*settings, account, true);
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
// See Folder::saveToSettings for details about why this exists.
|
|
|
|
settings->beginGroup(QLatin1String("Multifolders"));
|
|
|
|
setupFoldersHelper(*settings, account, false);
|
|
|
|
settings->endGroup();
|
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
settings->endGroup(); // <account>
|
|
|
|
}
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2015-12-08 16:37:37 +03:00
|
|
|
emit folderListChanged(_folderMap);
|
2015-04-24 11:18:33 +03:00
|
|
|
|
|
|
|
return _folderMap.size();
|
|
|
|
}
|
|
|
|
|
2016-11-23 12:40:17 +03:00
|
|
|
void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible)
|
2016-11-22 17:30:12 +03:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (const auto &folderAlias, settings.childGroups()) {
|
2016-11-22 17:30:12 +03:00
|
|
|
FolderDefinition folderDefinition;
|
|
|
|
if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
|
2017-06-16 16:43:21 +03:00
|
|
|
auto defaultJournalPath = folderDefinition.defaultJournalPath(account->account());
|
|
|
|
|
2016-11-23 12:40:17 +03:00
|
|
|
// Migration: Old settings don't have journalPath
|
|
|
|
if (folderDefinition.journalPath.isEmpty()) {
|
2017-06-16 16:43:21 +03:00
|
|
|
folderDefinition.journalPath = defaultJournalPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Migration: ._ files sometimes don't work
|
|
|
|
// So if the configured journalPath is the default one ("._sync_*.db")
|
|
|
|
// but the current default doesn't have the underscore, switch to the
|
|
|
|
// new default. See SyncJournalDb::makeDbName().
|
|
|
|
if (folderDefinition.journalPath.startsWith("._sync_")
|
|
|
|
&& defaultJournalPath.startsWith(".sync_")) {
|
|
|
|
folderDefinition.journalPath = defaultJournalPath;
|
2016-11-23 12:40:17 +03:00
|
|
|
}
|
2017-06-16 16:43:21 +03:00
|
|
|
|
2016-11-23 12:40:17 +03:00
|
|
|
// Migration: If an old db is found, move it to the new name.
|
|
|
|
if (backwardsCompatible) {
|
|
|
|
SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath());
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *f = addFolderInternal(std::move(folderDefinition), account.data());
|
2016-11-22 17:30:12 +03:00
|
|
|
if (f) {
|
2016-11-23 12:40:17 +03:00
|
|
|
// Migration: Mark folders that shall be saved in a backwards-compatible way
|
|
|
|
if (backwardsCompatible) {
|
|
|
|
f->setSaveBackwardsCompatible(true);
|
|
|
|
}
|
2016-11-22 17:30:12 +03:00
|
|
|
scheduleFolder(f);
|
|
|
|
emit folderSyncStateChange(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
int FolderMan::setupFoldersMigration()
|
|
|
|
{
|
|
|
|
ConfigFile cfg;
|
|
|
|
QDir storageDir(cfg.configPath());
|
|
|
|
_folderConfigPath = cfg.configPath() + QLatin1String("folders");
|
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Setup folders from " << _folderConfigPath << "(migration)";
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QDir dir(_folderConfigPath);
|
2015-04-24 11:18:33 +03:00
|
|
|
//We need to include hidden files just in case the alias starts with '.'
|
|
|
|
dir.setFilter(QDir::Files | QDir::Hidden);
|
|
|
|
QStringList list = dir.entryList();
|
|
|
|
|
2015-10-05 07:21:19 +03:00
|
|
|
// Normally there should be only one account when migrating.
|
2017-05-17 11:55:42 +03:00
|
|
|
AccountState *accountState = AccountManager::instance()->accounts().value(0).data();
|
|
|
|
foreach (const QString &alias, list) {
|
|
|
|
Folder *f = setupFolderFromOldConfigFile(alias, accountState);
|
|
|
|
if (f) {
|
2016-10-19 12:03:13 +03:00
|
|
|
scheduleFolder(f);
|
2015-09-04 11:33:48 +03:00
|
|
|
emit folderSyncStateChange(f);
|
2015-04-24 11:18:33 +03:00
|
|
|
}
|
2012-07-25 17:00:18 +04:00
|
|
|
}
|
2014-03-26 22:30:13 +04:00
|
|
|
|
2015-12-08 16:37:37 +03:00
|
|
|
emit folderListChanged(_folderMap);
|
2014-03-26 22:30:13 +04:00
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
// return the number of valid folders.
|
|
|
|
return _folderMap.size();
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
2014-01-20 18:12:26 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
bool FolderMan::ensureJournalGone(const QString &journalDbFile)
|
2013-06-06 19:59:50 +04:00
|
|
|
{
|
2016-09-02 16:51:13 +03:00
|
|
|
// remove the old journal file
|
2016-09-02 13:29:21 +03:00
|
|
|
while (QFile::exists(journalDbFile) && !QFile::remove(journalDbFile)) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcFolderMan) << "Could not remove old db file at" << journalDbFile;
|
2013-06-06 19:59:50 +04:00
|
|
|
int ret = QMessageBox::warning(0, tr("Could not reset folder state"),
|
2017-05-17 11:55:42 +03:00
|
|
|
tr("An old sync journal '%1' was found, "
|
|
|
|
"but could not be removed. Please make sure "
|
|
|
|
"that no application is currently using it.")
|
|
|
|
.arg(QDir::fromNativeSeparators(QDir::cleanPath(journalDbFile))),
|
|
|
|
QMessageBox::Retry | QMessageBox::Abort);
|
2013-06-06 19:59:50 +04:00
|
|
|
if (ret == QMessageBox::Abort) {
|
2013-06-06 23:43:05 +04:00
|
|
|
return false;
|
2013-06-06 19:59:50 +04:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 23:43:05 +04:00
|
|
|
return true;
|
2013-06-06 19:59:50 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
#define SLASH_TAG QLatin1String("__SLASH__")
|
|
|
|
#define BSLASH_TAG QLatin1String("__BSLASH__")
|
|
|
|
#define QMARK_TAG QLatin1String("__QMARK__")
|
2012-10-17 17:13:55 +04:00
|
|
|
#define PERCENT_TAG QLatin1String("__PERCENT__")
|
2017-05-17 11:55:42 +03:00
|
|
|
#define STAR_TAG QLatin1String("__STAR__")
|
|
|
|
#define COLON_TAG QLatin1String("__COLON__")
|
|
|
|
#define PIPE_TAG QLatin1String("__PIPE__")
|
|
|
|
#define QUOTE_TAG QLatin1String("__QUOTE__")
|
|
|
|
#define LT_TAG QLatin1String("__LESS_THAN__")
|
|
|
|
#define GT_TAG QLatin1String("__GREATER_THAN__")
|
|
|
|
#define PAR_O_TAG QLatin1String("__PAR_OPEN__")
|
|
|
|
#define PAR_C_TAG QLatin1String("__PAR_CLOSE__")
|
|
|
|
|
|
|
|
QString FolderMan::escapeAlias(const QString &alias)
|
2012-10-17 17:13:55 +04:00
|
|
|
{
|
|
|
|
QString a(alias);
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
a.replace(QLatin1Char('/'), SLASH_TAG);
|
|
|
|
a.replace(QLatin1Char('\\'), BSLASH_TAG);
|
|
|
|
a.replace(QLatin1Char('?'), QMARK_TAG);
|
|
|
|
a.replace(QLatin1Char('%'), PERCENT_TAG);
|
|
|
|
a.replace(QLatin1Char('*'), STAR_TAG);
|
|
|
|
a.replace(QLatin1Char(':'), COLON_TAG);
|
|
|
|
a.replace(QLatin1Char('|'), PIPE_TAG);
|
|
|
|
a.replace(QLatin1Char('"'), QUOTE_TAG);
|
|
|
|
a.replace(QLatin1Char('<'), LT_TAG);
|
|
|
|
a.replace(QLatin1Char('>'), GT_TAG);
|
|
|
|
a.replace(QLatin1Char('['), PAR_O_TAG);
|
|
|
|
a.replace(QLatin1Char(']'), PAR_C_TAG);
|
2012-10-17 17:13:55 +04:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
SocketApi *FolderMan::socketApi()
|
|
|
|
{
|
2016-03-18 20:31:01 +03:00
|
|
|
return this->_socketApi.data();
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QString FolderMan::unescapeAlias(const QString &alias)
|
2012-10-17 17:13:55 +04:00
|
|
|
{
|
|
|
|
QString a(alias);
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
a.replace(SLASH_TAG, QLatin1String("/"));
|
|
|
|
a.replace(BSLASH_TAG, QLatin1String("\\"));
|
|
|
|
a.replace(QMARK_TAG, QLatin1String("?"));
|
|
|
|
a.replace(PERCENT_TAG, QLatin1String("%"));
|
|
|
|
a.replace(STAR_TAG, QLatin1String("*"));
|
|
|
|
a.replace(COLON_TAG, QLatin1String(":"));
|
|
|
|
a.replace(PIPE_TAG, QLatin1String("|"));
|
|
|
|
a.replace(QUOTE_TAG, QLatin1String("\""));
|
|
|
|
a.replace(LT_TAG, QLatin1String("<"));
|
|
|
|
a.replace(GT_TAG, QLatin1String(">"));
|
|
|
|
a.replace(PAR_O_TAG, QLatin1String("["));
|
|
|
|
a.replace(PAR_C_TAG, QLatin1String("]"));
|
2012-10-17 17:13:55 +04:00
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-02-17 12:48:31 +04:00
|
|
|
// filename is the name of the file only, it does not include
|
|
|
|
// the configuration directory path
|
2016-11-16 16:08:05 +03:00
|
|
|
// WARNING: Do not remove this code, it is used for predefined/automated deployments (2016)
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountState *accountState)
|
2015-05-12 17:48:19 +03:00
|
|
|
{
|
2012-10-17 17:13:55 +04:00
|
|
|
Folder *folder = 0;
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << " ` -> setting up:" << file;
|
2012-10-17 17:13:55 +04:00
|
|
|
QString escapedAlias(file);
|
2015-10-05 07:21:19 +03:00
|
|
|
// check the unescaped variant (for the case when the filename comes out
|
|
|
|
// of the directory listing). If the file does not exist, escape the
|
2012-10-17 17:13:55 +04:00
|
|
|
// file and try again.
|
2017-05-17 11:55:42 +03:00
|
|
|
QFileInfo cfgFile(_folderConfigPath, file);
|
2012-10-17 17:13:55 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!cfgFile.exists()) {
|
2012-10-17 17:13:55 +04:00
|
|
|
// try the escaped variant.
|
|
|
|
escapedAlias = escapeAlias(file);
|
2017-05-17 11:55:42 +03:00
|
|
|
cfgFile.setFile(_folderConfigPath, escapedAlias);
|
2012-10-17 17:13:55 +04:00
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!cfgFile.isReadable()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcFolderMan) << "Cannot read folder definition for alias " << cfgFile.filePath();
|
2012-10-17 17:13:55 +04:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QSettings settings(_folderConfigPath + QLatin1Char('/') + escapedAlias, QSettings::IniFormat);
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << " -> file path: " << settings.fileName();
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2012-11-22 15:31:29 +04:00
|
|
|
// Check if the filename is equal to the group setting. If not, use the group
|
|
|
|
// name as an alias.
|
|
|
|
QStringList groups = settings.childGroups();
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!groups.contains(escapedAlias) && groups.count() > 0) {
|
2012-11-22 15:31:29 +04:00
|
|
|
escapedAlias = groups.first();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
settings.beginGroup(escapedAlias); // read the group with the same name as the file which is the folder alias
|
2012-02-17 12:48:31 +04:00
|
|
|
|
2013-09-09 16:00:13 +04:00
|
|
|
QString path = settings.value(QLatin1String("localPath")).toString();
|
2012-08-17 19:13:17 +04:00
|
|
|
QString backend = settings.value(QLatin1String("backend")).toString();
|
2017-05-17 11:55:42 +03:00
|
|
|
QString targetPath = settings.value(QLatin1String("targetPath")).toString();
|
|
|
|
bool paused = settings.value(QLatin1String("paused"), false).toBool();
|
2012-10-17 17:13:55 +04:00
|
|
|
// QString connection = settings.value( QLatin1String("connection") ).toString();
|
2017-05-17 11:55:42 +03:00
|
|
|
QString alias = unescapeAlias(escapedAlias);
|
2012-02-17 14:11:18 +04:00
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
if (backend.isEmpty() || backend != QLatin1String("owncloud")) {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCWarning(lcFolderMan) << "obsolete configuration of type" << backend;
|
2013-07-22 22:27:42 +04:00
|
|
|
return 0;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2013-07-22 22:27:42 +04:00
|
|
|
// cut off the leading slash, oCUrl always has a trailing.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (targetPath.startsWith(QLatin1Char('/'))) {
|
|
|
|
targetPath.remove(0, 1);
|
2013-07-22 22:27:42 +04:00
|
|
|
}
|
2013-02-10 17:57:57 +04:00
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
if (!accountState) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCCritical(lcFolderMan) << "can't create folder without an account";
|
2014-12-18 14:09:48 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-24 11:18:33 +03:00
|
|
|
FolderDefinition folderDefinition;
|
|
|
|
folderDefinition.alias = alias;
|
|
|
|
folderDefinition.localPath = path;
|
|
|
|
folderDefinition.targetPath = targetPath;
|
2015-06-17 16:55:48 +03:00
|
|
|
folderDefinition.paused = paused;
|
2015-08-10 12:03:57 +03:00
|
|
|
folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles();
|
2015-06-17 15:53:58 +03:00
|
|
|
|
2016-03-16 21:07:40 +03:00
|
|
|
folder = addFolderInternal(folderDefinition, accountState);
|
2015-06-17 16:55:48 +03:00
|
|
|
if (folder) {
|
2017-05-17 11:55:42 +03:00
|
|
|
QStringList blackList = settings.value(QLatin1String("blackList")).toStringList();
|
2015-06-17 15:53:58 +03:00
|
|
|
if (!blackList.empty()) {
|
|
|
|
//migrate settings
|
|
|
|
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
|
|
|
|
settings.remove(QLatin1String("blackList"));
|
2016-11-16 16:08:05 +03:00
|
|
|
// FIXME: If you remove this codepath, you need to provide another way to do
|
|
|
|
// this via theme.h or the normal FolderMan::setupFolders
|
2015-06-17 15:53:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
folder->saveToSettings();
|
2015-05-21 13:22:50 +03:00
|
|
|
}
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Migrated!" << folder;
|
2015-07-31 18:09:56 +03:00
|
|
|
settings.sync();
|
2012-02-17 12:48:31 +04:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotFolderSyncPaused(Folder *f, bool paused)
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!f) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCCritical(lcFolderMan) << "slotFolderSyncPaused called with empty folder";
|
2015-01-16 14:23:15 +03:00
|
|
|
return;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
if (!paused) {
|
|
|
|
_disabledFolders.remove(f);
|
2016-10-19 12:03:13 +03:00
|
|
|
scheduleFolder(f);
|
2015-01-16 14:23:15 +03:00
|
|
|
} else {
|
|
|
|
_disabledFolders.insert(f);
|
2012-04-30 10:56:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 23:43:53 +03:00
|
|
|
void FolderMan::slotFolderCanSyncChanged()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *f = qobject_cast<Folder *>(sender());
|
2017-02-07 15:52:15 +03:00
|
|
|
ASSERT(f);
|
2016-04-28 23:43:53 +03:00
|
|
|
if (f->canSync()) {
|
|
|
|
_socketApi->slotRegisterPath(f->alias());
|
|
|
|
} else {
|
|
|
|
_socketApi->slotUnregisterPath(f->alias());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:58:38 +03:00
|
|
|
// this really terminates the current sync process
|
|
|
|
// ie. no questions, no prisoners
|
2012-04-30 10:56:56 +04:00
|
|
|
// csync still remains in a stable state, regardless of that.
|
2014-11-21 14:58:38 +03:00
|
|
|
void FolderMan::terminateSyncProcess()
|
2012-04-30 10:56:56 +04:00
|
|
|
{
|
2015-04-28 16:13:39 +03:00
|
|
|
Folder *f = _currentSyncFolder;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (f) {
|
2015-01-16 14:23:15 +03:00
|
|
|
// This will, indirectly and eventually, call slotFolderSyncFinished
|
|
|
|
// and thereby clear _currentSyncFolder.
|
|
|
|
f->slotTerminateSync();
|
2012-04-30 10:56:56 +04:00
|
|
|
}
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *FolderMan::folder(const QString &alias)
|
2012-02-21 14:50:19 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!alias.isEmpty()) {
|
|
|
|
if (_folderMap.contains(alias)) {
|
2012-02-21 14:50:19 +04:00
|
|
|
return _folderMap[alias];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-19 12:03:13 +03:00
|
|
|
void FolderMan::scheduleAllFolders()
|
2013-02-19 20:24:10 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *f, _folderMap.values()) {
|
2015-07-01 12:39:57 +03:00
|
|
|
if (f && f->canSync()) {
|
2017-05-17 11:55:42 +03:00
|
|
|
scheduleFolder(f);
|
2013-08-05 15:34:36 +04:00
|
|
|
}
|
2013-02-19 20:24:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 13:12:00 +03:00
|
|
|
void FolderMan::slotScheduleAppRestart()
|
|
|
|
{
|
|
|
|
_appRestartRequired = true;
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Application restart requested!";
|
2015-07-17 13:12:00 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotSyncOnceFileUnlocks(const QString &path)
|
2016-04-29 17:14:18 +03:00
|
|
|
{
|
|
|
|
_lockWatcher->addFile(path);
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
/*
|
|
|
|
* if a folder wants to be synced, it calls this slot and is added
|
|
|
|
* to the queue. The slot to actually start a sync is called afterwards.
|
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::scheduleFolder(Folder *f)
|
2012-03-22 19:22:08 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!f) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCCritical(lcFolderMan) << "slotScheduleSync called with null folder";
|
2014-05-15 21:29:40 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-04-28 16:13:39 +03:00
|
|
|
auto alias = f->alias();
|
2014-09-17 15:02:11 +04:00
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Schedule folder " << alias << " to sync!";
|
2012-03-22 19:22:08 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!_scheduledFolders.contains(f)) {
|
|
|
|
if (!f->canSync()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Folder is not ready to sync, not scheduled!";
|
2016-03-18 20:31:01 +03:00
|
|
|
_socketApi->slotUpdateFolderView(f);
|
2014-09-17 15:02:11 +04:00
|
|
|
return;
|
2014-01-11 23:35:16 +04:00
|
|
|
}
|
2015-09-04 11:33:48 +03:00
|
|
|
f->prepareToSync();
|
|
|
|
emit folderSyncStateChange(f);
|
2016-10-18 17:04:25 +03:00
|
|
|
_scheduledFolders.enqueue(f);
|
2015-09-04 11:33:48 +03:00
|
|
|
emit scheduleQueueChanged();
|
2012-03-29 12:13:19 +04:00
|
|
|
} else {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Sync for folder " << alias << " already scheduled, do not enqueue!";
|
2012-03-29 12:13:19 +04:00
|
|
|
}
|
2014-09-17 15:02:11 +04:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
startScheduledSyncSoon();
|
2012-03-22 19:22:08 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::scheduleFolderNext(Folder *f)
|
2016-11-25 16:23:56 +03:00
|
|
|
{
|
|
|
|
auto alias = f->alias();
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Schedule folder " << alias << " to sync! Front-of-queue.";
|
2016-11-25 16:23:56 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!f->canSync()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Folder is not ready to sync, not scheduled!";
|
2016-11-25 16:23:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_scheduledFolders.removeAll(f);
|
|
|
|
|
|
|
|
f->prepareToSync();
|
|
|
|
emit folderSyncStateChange(f);
|
|
|
|
_scheduledFolders.prepend(f);
|
|
|
|
emit scheduleQueueChanged();
|
|
|
|
|
|
|
|
startScheduledSyncSoon();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotScheduleETagJob(const QString & /*alias*/, RequestEtagJob *job)
|
2014-12-03 00:32:54 +03:00
|
|
|
{
|
2017-09-20 11:14:48 +03:00
|
|
|
QObject::connect(job, &QObject::destroyed, this, &FolderMan::slotEtagJobDestroyed);
|
2014-12-03 00:32:54 +03:00
|
|
|
QMetaObject::invokeMethod(this, "slotRunOneEtagJob", Qt::QueuedConnection);
|
2014-12-03 16:56:46 +03:00
|
|
|
// maybe: add to queue
|
2014-12-03 00:32:54 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotEtagJobDestroyed(QObject * /*o*/)
|
2014-12-03 00:32:54 +03:00
|
|
|
{
|
2014-12-03 16:56:46 +03:00
|
|
|
// _currentEtagJob is automatically cleared
|
|
|
|
// maybe: remove from queue
|
2014-12-03 00:32:54 +03:00
|
|
|
QMetaObject::invokeMethod(this, "slotRunOneEtagJob", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderMan::slotRunOneEtagJob()
|
|
|
|
{
|
|
|
|
if (_currentEtagJob.isNull()) {
|
2016-01-05 17:11:46 +03:00
|
|
|
Folder *folder;
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *f, _folderMap) {
|
2014-12-03 00:32:54 +03:00
|
|
|
if (f->etagJob()) {
|
|
|
|
// Caveat: always grabs the first folder with a job, but we think this is Ok for now and avoids us having a seperate queue.
|
|
|
|
_currentEtagJob = f->etagJob();
|
2016-01-05 17:11:46 +03:00
|
|
|
folder = f;
|
2014-12-03 00:32:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_currentEtagJob.isNull()) {
|
2017-05-09 15:24:11 +03:00
|
|
|
//qCDebug(lcFolderMan) << "No more remote ETag check jobs to schedule.";
|
2015-07-17 13:12:00 +03:00
|
|
|
|
|
|
|
/* now it might be a good time to check for restarting... */
|
2017-05-17 11:55:42 +03:00
|
|
|
if (_currentSyncFolder == NULL && _appRestartRequired) {
|
2015-07-17 13:12:00 +03:00
|
|
|
restartApplication();
|
|
|
|
}
|
2014-12-03 00:32:54 +03:00
|
|
|
} else {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcFolderMan) << "Scheduling" << folder->remoteUrl().toString() << "to check remote ETag";
|
2014-12-03 00:32:54 +03:00
|
|
|
_currentEtagJob->start(); // on destroy/end it will continue the queue via slotEtagJobDestroyed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-01 12:39:57 +03:00
|
|
|
void FolderMan::slotAccountStateChanged()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
AccountState *accountState = qobject_cast<AccountState *>(sender());
|
|
|
|
if (!accountState) {
|
2015-07-01 12:39:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString accountName = accountState->account()->displayName();
|
|
|
|
|
2016-04-28 23:43:53 +03:00
|
|
|
if (accountState->isConnected()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Account" << accountName << "connected, scheduling its folders";
|
2015-07-01 12:39:57 +03:00
|
|
|
|
|
|
|
foreach (Folder *f, _folderMap.values()) {
|
|
|
|
if (f
|
2017-05-17 11:55:42 +03:00
|
|
|
&& f->canSync()
|
|
|
|
&& f->accountState() == accountState) {
|
2016-10-19 12:03:13 +03:00
|
|
|
scheduleFolder(f);
|
2015-07-01 12:39:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Account" << accountName << "disconnected or paused, "
|
2017-05-17 11:55:42 +03:00
|
|
|
"terminating or descheduling sync folders";
|
2015-07-01 12:39:57 +03:00
|
|
|
|
|
|
|
if (_currentSyncFolder
|
2017-05-17 11:55:42 +03:00
|
|
|
&& _currentSyncFolder->accountState() == accountState) {
|
2015-07-01 12:39:57 +03:00
|
|
|
_currentSyncFolder->slotTerminateSync();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QMutableListIterator<Folder *> it(_scheduledFolders);
|
2015-07-01 12:39:57 +03:00
|
|
|
while (it.hasNext()) {
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *f = it.next();
|
2015-07-01 12:39:57 +03:00
|
|
|
if (f->accountState() == accountState) {
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 11:33:48 +03:00
|
|
|
emit scheduleQueueChanged();
|
2015-07-01 12:39:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:19 +03:00
|
|
|
// only enable or disable foldermans will schedule and do syncs.
|
2014-08-19 16:03:41 +04:00
|
|
|
// this is not the same as Pause and Resume of folders.
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::setSyncEnabled(bool enabled)
|
2013-02-10 14:00:22 +04:00
|
|
|
{
|
2016-10-18 17:04:25 +03:00
|
|
|
if (!_syncEnabled && enabled && !_scheduledFolders.isEmpty()) {
|
2015-10-05 07:21:19 +03:00
|
|
|
// We have things in our queue that were waiting for the connection to come back on.
|
2015-01-16 14:23:15 +03:00
|
|
|
startScheduledSyncSoon();
|
2013-08-14 14:59:56 +04:00
|
|
|
}
|
2013-02-10 14:00:22 +04:00
|
|
|
_syncEnabled = enabled;
|
2014-08-19 16:03:41 +04:00
|
|
|
// force a redraw in case the network connect status changed
|
2017-05-17 11:55:42 +03:00
|
|
|
emit(folderSyncStateChange(0));
|
2013-02-10 14:00:22 +04:00
|
|
|
}
|
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
void FolderMan::startScheduledSyncSoon()
|
2015-01-16 14:23:15 +03:00
|
|
|
{
|
|
|
|
if (_startScheduledSyncTimer.isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-18 17:04:25 +03:00
|
|
|
if (_scheduledFolders.empty()) {
|
2015-01-16 14:23:15 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-04-28 16:13:39 +03:00
|
|
|
if (_currentSyncFolder) {
|
2015-01-16 14:23:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
qint64 msDelay = 100; // 100ms minimum delay
|
2015-01-16 14:23:15 +03:00
|
|
|
qint64 msSinceLastSync = 0;
|
|
|
|
|
|
|
|
// Require a pause based on the duration of the last sync run.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (Folder *lastFolder = _lastSyncFolder) {
|
2015-01-16 14:23:15 +03:00
|
|
|
msSinceLastSync = lastFolder->msecSinceLastSync();
|
|
|
|
|
|
|
|
// 1s -> 1.5s pause
|
|
|
|
// 10s -> 5s pause
|
|
|
|
// 1min -> 12s pause
|
|
|
|
// 1h -> 90s pause
|
|
|
|
qint64 pause = qSqrt(lastFolder->msecLastSyncDuration()) / 20.0 * 1000.0;
|
|
|
|
msDelay = qMax(msDelay, pause);
|
|
|
|
}
|
|
|
|
|
2015-01-16 14:45:12 +03:00
|
|
|
// Delays beyond one minute seem too big, particularly since there
|
|
|
|
// could be things later in the queue that shouldn't be punished by a
|
|
|
|
// long delay!
|
2017-05-17 11:55:42 +03:00
|
|
|
msDelay = qMin(msDelay, 60 * 1000ll);
|
2015-01-16 14:23:15 +03:00
|
|
|
|
2015-01-28 13:23:20 +03:00
|
|
|
// Time since the last sync run counts against the delay
|
2015-01-16 14:23:15 +03:00
|
|
|
msDelay = qMax(1ll, msDelay - msSinceLastSync);
|
2015-01-28 13:23:20 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
qCInfo(lcFolderMan) << "Starting the next scheduled sync in" << (msDelay / 1000) << "seconds";
|
2015-01-16 14:23:15 +03:00
|
|
|
_startScheduledSyncTimer.start(msDelay);
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
/*
|
|
|
|
* slot to start folder syncs.
|
|
|
|
* It is either called from the slot where folders enqueue themselves for
|
|
|
|
* syncing or after a folder sync was finished.
|
|
|
|
*/
|
2014-09-17 15:02:11 +04:00
|
|
|
void FolderMan::slotStartScheduledFolderSync()
|
2012-03-22 19:22:08 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (_currentSyncFolder) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Currently folder " << _currentSyncFolder->remoteUrl().toString() << " is running, wait for finish!";
|
2012-03-22 19:22:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!_syncEnabled) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "FolderMan: Syncing is disabled, no scheduling.";
|
2013-02-10 14:00:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCDebug(lcFolderMan) << "folderQueue size: " << _scheduledFolders.count();
|
2017-05-17 11:55:42 +03:00
|
|
|
if (_scheduledFolders.isEmpty()) {
|
2015-01-16 14:23:15 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2015-11-11 12:56:19 +03:00
|
|
|
// Find the first folder in the queue that can be synced.
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *folder = 0;
|
|
|
|
while (!_scheduledFolders.isEmpty()) {
|
|
|
|
Folder *g = _scheduledFolders.dequeue();
|
|
|
|
if (g->canSync()) {
|
2016-11-22 12:53:15 +03:00
|
|
|
folder = g;
|
2015-11-11 12:56:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 11:33:48 +03:00
|
|
|
emit scheduleQueueChanged();
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
// Start syncing this folder!
|
2017-05-17 11:55:42 +03:00
|
|
|
if (folder) {
|
2016-12-06 15:45:01 +03:00
|
|
|
// Safe to call several times, and necessary to try again if
|
|
|
|
// the folder path didn't exist previously.
|
2017-10-09 13:06:11 +03:00
|
|
|
folder->registerFolderWatcher();
|
|
|
|
registerFolderWithSocketApi(folder);
|
2016-12-06 15:45:01 +03:00
|
|
|
|
2016-11-22 12:53:15 +03:00
|
|
|
_currentSyncFolder = folder;
|
2017-05-17 11:55:42 +03:00
|
|
|
folder->startSync(QStringList());
|
2012-03-22 19:22:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 00:32:54 +03:00
|
|
|
void FolderMan::slotEtagPollTimerTimeout()
|
|
|
|
{
|
2014-12-10 15:01:36 +03:00
|
|
|
ConfigFile cfg;
|
2014-12-03 00:32:54 +03:00
|
|
|
int polltime = cfg.remotePollInterval();
|
|
|
|
|
2015-04-28 16:13:39 +03:00
|
|
|
foreach (Folder *f, _folderMap) {
|
2015-07-01 12:39:57 +03:00
|
|
|
if (!f) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-28 16:13:39 +03:00
|
|
|
if (_currentSyncFolder == f) {
|
2014-12-03 00:32:54 +03:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-18 17:04:25 +03:00
|
|
|
if (_scheduledFolders.contains(f)) {
|
2014-12-03 00:32:54 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-01 12:39:57 +03:00
|
|
|
if (_disabledFolders.contains(f)) {
|
2014-12-03 00:32:54 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-01 12:39:57 +03:00
|
|
|
if (f->etagJob() || f->isBusy() || !f->canSync()) {
|
2014-12-03 00:32:54 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-01 12:39:57 +03:00
|
|
|
if (f->msecSinceLastSync() < polltime) {
|
2014-12-03 00:32:54 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-28 16:13:39 +03:00
|
|
|
QMetaObject::invokeMethod(f, "slotRunEtagJob", Qt::QueuedConnection);
|
2014-12-03 00:32:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotRemoveFoldersForAccount(AccountState *accountState)
|
2014-12-18 14:09:48 +03:00
|
|
|
{
|
2015-04-28 16:13:39 +03:00
|
|
|
QVarLengthArray<Folder *, 16> foldersToRemove;
|
2014-12-18 14:09:48 +03:00
|
|
|
Folder::MapIterator i(_folderMap);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *folder = i.value();
|
2014-12-18 14:09:48 +03:00
|
|
|
if (folder->accountState() == accountState) {
|
2015-04-28 16:13:39 +03:00
|
|
|
foldersToRemove.append(folder);
|
2014-12-18 14:09:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 16:13:39 +03:00
|
|
|
foreach (const auto &f, foldersToRemove) {
|
2016-10-19 12:03:13 +03:00
|
|
|
removeFolder(f);
|
2014-12-18 14:09:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 16:55:48 +03:00
|
|
|
void FolderMan::slotForwardFolderSyncStateChange()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (Folder *f = qobject_cast<Folder *>(sender())) {
|
2015-06-17 16:55:48 +03:00
|
|
|
emit folderSyncStateChange(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 13:59:36 +03:00
|
|
|
void FolderMan::slotServerVersionChanged(Account *account)
|
|
|
|
{
|
|
|
|
// Pause folders if the server version is unsupported
|
|
|
|
if (account->serverVersionUnsupported()) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcFolderMan) << "The server version is unsupported:" << account->serverVersion()
|
2017-05-17 11:55:42 +03:00
|
|
|
<< "pausing all folders on the account";
|
2016-03-02 13:59:36 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (auto &f, _folderMap) {
|
2016-03-02 13:59:36 +03:00
|
|
|
if (f->accountState()->account().data() == account) {
|
|
|
|
f->setSyncPaused(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotWatchedFileUnlocked(const QString &path)
|
2016-04-29 17:14:18 +03:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (Folder *f = folderForPath(path)) {
|
2016-10-18 17:04:25 +03:00
|
|
|
f->scheduleThisFolderSoon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderMan::slotScheduleFolderByTime()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (auto &f, _folderMap) {
|
2016-10-18 17:04:25 +03:00
|
|
|
// Never schedule if syncing is disabled or when we're currently
|
|
|
|
// querying the server for etags
|
|
|
|
if (!f->canSync() || f->etagJob()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto msecsSinceSync = f->msecSinceLastSync();
|
|
|
|
|
|
|
|
// Possibly it's just time for a new sync run
|
|
|
|
bool forceSyncIntervalExpired =
|
2017-05-17 11:55:42 +03:00
|
|
|
quint64(msecsSinceSync) > ConfigFile().forceSyncInterval();
|
2016-10-18 17:04:25 +03:00
|
|
|
if (forceSyncIntervalExpired) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Scheduling folder" << f->alias()
|
2017-05-17 11:55:42 +03:00
|
|
|
<< "because it has been" << msecsSinceSync << "ms "
|
|
|
|
<< "since the last sync";
|
2016-10-18 17:04:25 +03:00
|
|
|
|
2016-10-19 12:03:13 +03:00
|
|
|
scheduleFolder(f);
|
2016-10-18 17:04:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-06 15:18:59 +03:00
|
|
|
// Retry a couple of times after failure; or regularly if requested
|
|
|
|
bool syncAgain =
|
2017-05-17 11:55:42 +03:00
|
|
|
(f->consecutiveFailingSyncs() > 0 && f->consecutiveFailingSyncs() < 3)
|
|
|
|
|| f->syncEngine().isAnotherSyncNeeded() == DelayedFollowUp;
|
2016-12-06 15:18:59 +03:00
|
|
|
qint64 syncAgainDelay = 10 * 1000; // 10s for the first retry-after-fail
|
2016-10-18 17:04:25 +03:00
|
|
|
if (f->consecutiveFailingSyncs() > 1)
|
2016-12-06 15:18:59 +03:00
|
|
|
syncAgainDelay = 60 * 1000; // 60s for each further attempt
|
|
|
|
if (syncAgain
|
2017-05-17 11:55:42 +03:00
|
|
|
&& msecsSinceSync > syncAgainDelay) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Scheduling folder" << f->alias()
|
2017-05-17 11:55:42 +03:00
|
|
|
<< ", the last" << f->consecutiveFailingSyncs() << "syncs failed"
|
|
|
|
<< ", anotherSyncNeeded" << f->syncEngine().isAnotherSyncNeeded()
|
|
|
|
<< ", last status:" << f->syncResult().statusString()
|
|
|
|
<< ", time since last sync:" << msecsSinceSync;
|
2016-10-18 17:04:25 +03:00
|
|
|
|
2016-10-19 12:03:13 +03:00
|
|
|
scheduleFolder(f);
|
2016-10-18 17:04:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we want to retry failing syncs or another-sync-needed runs more often?
|
2016-04-29 17:14:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotFolderSyncStarted()
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2017-05-16 18:42:57 +03:00
|
|
|
qCInfo(lcFolderMan, ">========== Sync started for folder [%s] of account [%s] with remote [%s]",
|
|
|
|
qPrintable(_currentSyncFolder->shortGuiLocalPath()),
|
|
|
|
qPrintable(_currentSyncFolder->accountState()->account()->displayName()),
|
|
|
|
qPrintable(_currentSyncFolder->remoteUrl().toString()));
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
/*
|
|
|
|
* a folder indicates that its syncing is finished.
|
|
|
|
* Start the next sync after the system had some milliseconds to breath.
|
2014-10-09 17:50:29 +04:00
|
|
|
* This delay is particularly useful to avoid late file change notifications
|
|
|
|
* (that we caused ourselves by syncing) from triggering another spurious sync.
|
2012-03-22 19:22:08 +04:00
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::slotFolderSyncFinished(const SyncResult &)
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2017-05-16 18:42:57 +03:00
|
|
|
qCInfo(lcFolderMan, "<========== Sync finished for folder [%s] of account [%s] with remote [%s]",
|
|
|
|
qPrintable(_currentSyncFolder->shortGuiLocalPath()),
|
|
|
|
qPrintable(_currentSyncFolder->accountState()->account()->displayName()),
|
|
|
|
qPrintable(_currentSyncFolder->remoteUrl().toString()));
|
2012-03-29 12:13:19 +04:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
_lastSyncFolder = _currentSyncFolder;
|
2015-04-28 16:13:39 +03:00
|
|
|
_currentSyncFolder = 0;
|
2014-01-11 23:35:16 +04:00
|
|
|
|
2015-01-16 14:23:15 +03:00
|
|
|
startScheduledSyncSoon();
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition)
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2016-11-23 12:40:17 +03:00
|
|
|
// Choose a db filename
|
|
|
|
auto definition = folderDefinition;
|
|
|
|
definition.journalPath = definition.defaultJournalPath(accountState->account());
|
|
|
|
|
|
|
|
if (!ensureJournalGone(definition.absoluteJournalPath())) {
|
2015-04-24 11:18:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-12-11 14:28:01 +03:00
|
|
|
|
2016-11-23 12:40:17 +03:00
|
|
|
auto folder = addFolderInternal(definition, accountState);
|
|
|
|
|
|
|
|
// Migration: The first account that's configured for a local folder shall
|
|
|
|
// be saved in a backwards-compatible way.
|
|
|
|
bool oneAccountOnly = true;
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *other, FolderMan::instance()->map()) {
|
2016-11-23 12:40:17 +03:00
|
|
|
if (other != folder && other->cleanPath() == folder->cleanPath()) {
|
|
|
|
oneAccountOnly = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
folder->setSaveBackwardsCompatible(oneAccountOnly);
|
2016-09-02 13:29:21 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (folder) {
|
2015-06-17 15:54:39 +03:00
|
|
|
folder->saveToSettings();
|
2015-12-08 16:37:37 +03:00
|
|
|
emit folderSyncStateChange(folder);
|
|
|
|
emit folderListChanged(_folderMap);
|
2015-06-17 15:53:58 +03:00
|
|
|
}
|
2017-10-04 14:49:42 +03:00
|
|
|
|
|
|
|
_navigationPaneHelper.scheduleUpdateCloudStorageRegistry();
|
|
|
|
|
2015-04-27 15:34:39 +03:00
|
|
|
return folder;
|
2015-04-24 11:18:33 +03:00
|
|
|
}
|
2014-12-11 14:28:01 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
Folder *FolderMan::addFolderInternal(FolderDefinition folderDefinition,
|
|
|
|
AccountState *accountState)
|
2015-04-24 11:18:33 +03:00
|
|
|
{
|
2016-04-26 17:09:39 +03:00
|
|
|
auto alias = folderDefinition.alias;
|
|
|
|
int count = 0;
|
|
|
|
while (folderDefinition.alias.isEmpty() || _folderMap.contains(folderDefinition.alias)) {
|
|
|
|
// There is already a folder configured with this name and folder names need to be unique
|
|
|
|
folderDefinition.alias = alias + QString::number(++count);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
auto folder = new Folder(folderDefinition, accountState, this);
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Adding folder to Folder Map " << folder << folder->alias();
|
2015-04-24 11:18:33 +03:00
|
|
|
_folderMap[folder->alias()] = folder;
|
2015-06-17 16:55:48 +03:00
|
|
|
if (folder->syncPaused()) {
|
2015-04-24 11:18:33 +03:00
|
|
|
_disabledFolders.insert(folder);
|
|
|
|
}
|
|
|
|
|
2015-06-17 16:55:48 +03:00
|
|
|
// See matching disconnects in unloadFolder().
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(folder, &Folder::syncStarted, this, &FolderMan::slotFolderSyncStarted);
|
|
|
|
connect(folder, &Folder::syncFinished, this, &FolderMan::slotFolderSyncFinished);
|
|
|
|
connect(folder, &Folder::syncStateChange, this, &FolderMan::slotForwardFolderSyncStateChange);
|
|
|
|
connect(folder, &Folder::syncPausedChanged, this, &FolderMan::slotFolderSyncPaused);
|
|
|
|
connect(folder, &Folder::canSyncChanged, this, &FolderMan::slotFolderCanSyncChanged);
|
2017-09-20 12:48:13 +03:00
|
|
|
connect(&folder->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
|
|
|
|
_socketApi.data(), &SocketApi::broadcastStatusPushMessage);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(folder, &Folder::watchedFileChangedExternally,
|
|
|
|
&folder->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::slotPathTouched);
|
2015-04-24 11:18:33 +03:00
|
|
|
|
2017-10-09 13:06:11 +03:00
|
|
|
folder->registerFolderWatcher();
|
|
|
|
registerFolderWithSocketApi(folder);
|
2015-04-24 11:18:33 +03:00
|
|
|
return folder;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2014-07-01 18:24:14 +04:00
|
|
|
Folder *FolderMan::folderForPath(const QString &path)
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
QString absolutePath = QDir::cleanPath(path) + QLatin1Char('/');
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *folder, this->map().values()) {
|
|
|
|
const QString folderPath = folder->cleanPath() + QLatin1Char('/');
|
2014-07-14 17:13:28 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (absolutePath.startsWith(folderPath, (Utility::isWindows() || Utility::isMac()) ? Qt::CaseInsensitive : Qt::CaseSensitive)) {
|
2013-10-03 19:04:55 +04:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 19:51:08 +03:00
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QStringList FolderMan::findFileInLocalFolders(const QString &relPath, const AccountPtr acc)
|
2015-11-16 17:04:59 +03:00
|
|
|
{
|
|
|
|
QStringList re;
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *folder, this->map().values()) {
|
2015-11-24 16:24:18 +03:00
|
|
|
if (acc != 0 && folder->accountState()->account() != acc) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-16 17:04:59 +03:00
|
|
|
QString path = folder->cleanPath();
|
|
|
|
QString remRelPath;
|
2015-11-16 17:38:08 +03:00
|
|
|
// cut off the remote path from the server path.
|
2015-11-16 17:04:59 +03:00
|
|
|
remRelPath = relPath.mid(folder->remotePath().length());
|
2015-11-24 16:24:18 +03:00
|
|
|
path += "/";
|
2015-11-16 17:04:59 +03:00
|
|
|
path += remRelPath;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (QFile::exists(path)) {
|
|
|
|
re.append(path);
|
2015-11-16 17:04:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
void FolderMan::removeFolder(Folder *f)
|
2012-02-17 12:48:31 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!f) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCCritical(lcFolderMan) << "Can not remove null folder";
|
2015-02-27 12:42:59 +03:00
|
|
|
return;
|
2012-03-29 12:13:19 +04:00
|
|
|
}
|
|
|
|
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Removing " << f->alias();
|
2013-06-12 14:41:32 +04:00
|
|
|
|
2015-04-28 16:13:39 +03:00
|
|
|
const bool currentlyRunning = (_currentSyncFolder == f);
|
2017-05-17 11:55:42 +03:00
|
|
|
if (currentlyRunning) {
|
2015-02-27 12:42:59 +03:00
|
|
|
// abort the sync now
|
|
|
|
terminateSyncProcess();
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2016-10-18 17:04:25 +03:00
|
|
|
if (_scheduledFolders.removeAll(f) > 0) {
|
2015-09-04 11:33:48 +03:00
|
|
|
emit scheduleQueueChanged();
|
|
|
|
}
|
2014-03-10 15:22:06 +04:00
|
|
|
|
2015-02-27 12:42:59 +03:00
|
|
|
f->wipe();
|
|
|
|
f->setSyncPaused(true);
|
2014-07-15 18:06:06 +04:00
|
|
|
|
2015-02-27 12:42:59 +03:00
|
|
|
// remove the folder configuration
|
2015-04-24 11:18:33 +03:00
|
|
|
f->removeFromSettings();
|
2014-07-15 18:06:06 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
unloadFolder(f);
|
|
|
|
if (currentlyRunning) {
|
2015-09-18 15:34:01 +03:00
|
|
|
// We want to schedule the next folder once this is done
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(f, &Folder::syncFinished,
|
|
|
|
this, &FolderMan::slotFolderSyncFinished);
|
2015-09-18 15:34:01 +03:00
|
|
|
// Let the folder delete itself when done.
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(f, &Folder::syncFinished, f, &QObject::deleteLater);
|
2015-09-18 15:34:01 +03:00
|
|
|
} else {
|
2015-02-27 12:42:59 +03:00
|
|
|
delete f;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
2017-07-06 15:02:21 +03:00
|
|
|
|
2017-10-04 14:49:42 +03:00
|
|
|
_navigationPaneHelper.scheduleUpdateCloudStorageRegistry();
|
|
|
|
|
2017-07-06 15:02:21 +03:00
|
|
|
emit folderListChanged(_folderMap);
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QString FolderMan::getBackupName(QString fullPathName) const
|
2013-05-26 15:56:51 +04:00
|
|
|
{
|
2014-09-15 15:49:13 +04:00
|
|
|
if (fullPathName.endsWith("/"))
|
|
|
|
fullPathName.chop(1);
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (fullPathName.isEmpty())
|
|
|
|
return QString::null;
|
2013-05-26 15:56:51 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QString newName = fullPathName + tr(" (backup)");
|
|
|
|
QFileInfo fi(newName);
|
|
|
|
int cnt = 2;
|
|
|
|
do {
|
|
|
|
if (fi.exists()) {
|
|
|
|
newName = fullPathName + tr(" (backup %1)").arg(cnt++);
|
|
|
|
fi.setFile(newName);
|
|
|
|
}
|
|
|
|
} while (fi.exists());
|
2013-05-26 15:56:51 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
return newName;
|
2013-05-26 15:56:51 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
bool FolderMan::startFromScratch(const QString &localFolder)
|
2013-05-26 15:56:51 +04:00
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (localFolder.isEmpty()) {
|
2014-09-05 12:13:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-26 15:56:51 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QFileInfo fi(localFolder);
|
|
|
|
QDir parentDir(fi.dir());
|
2014-09-05 12:13:00 +04:00
|
|
|
QString folderName = fi.fileName();
|
|
|
|
|
|
|
|
// Adjust for case where localFolder ends with a /
|
2017-05-17 11:55:42 +03:00
|
|
|
if (fi.isDir()) {
|
2014-09-05 12:13:00 +04:00
|
|
|
folderName = parentDir.dirName();
|
|
|
|
parentDir.cdUp();
|
|
|
|
}
|
2013-06-03 17:47:07 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (fi.exists()) {
|
2014-09-05 12:13:00 +04:00
|
|
|
// It exists, but is empty -> just reuse it.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (fi.isDir() && fi.dir().count() == 0) {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcFolderMan) << "startFromScratch: Directory is empty!";
|
2013-06-03 17:47:07 +04:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-24 13:12:02 +04:00
|
|
|
// Disconnect the socket api from the database to avoid that locking of the
|
|
|
|
// db file does not allow to move this dir.
|
2016-03-18 20:31:01 +03:00
|
|
|
Folder *f = folderForPath(localFolder);
|
2017-05-17 11:55:42 +03:00
|
|
|
if (f) {
|
|
|
|
if (localFolder.startsWith(f->path())) {
|
2016-03-18 20:31:01 +03:00
|
|
|
_socketApi->slotUnregisterPath(f->alias());
|
2014-10-24 13:36:01 +04:00
|
|
|
}
|
2016-03-18 20:31:01 +03:00
|
|
|
f->journalDb()->close();
|
|
|
|
f->slotTerminateSync(); // Normally it should not be running, but viel hilft viel
|
2014-10-24 13:12:02 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 12:13:00 +04:00
|
|
|
// Make a backup of the folder/file.
|
2017-05-17 11:55:42 +03:00
|
|
|
QString newName = getBackupName(parentDir.absoluteFilePath(folderName));
|
2015-03-11 12:51:36 +03:00
|
|
|
QString renameError;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!FileSystem::rename(fi.absoluteFilePath(), newName, &renameError)) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcFolderMan) << "startFromScratch: Could not rename" << fi.absoluteFilePath()
|
2017-05-17 11:55:42 +03:00
|
|
|
<< "to" << newName << "error:" << renameError;
|
2014-09-05 12:13:00 +04:00
|
|
|
return false;
|
2013-05-26 15:56:51 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 12:13:00 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!parentDir.mkdir(fi.absoluteFilePath())) {
|
2017-03-30 14:46:20 +03:00
|
|
|
qCWarning(lcFolderMan) << "startFromScratch: Could not mkdir" << fi.absoluteFilePath();
|
2014-09-05 12:13:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-05-26 15:56:51 +04:00
|
|
|
}
|
|
|
|
|
2013-10-14 18:11:15 +04:00
|
|
|
void FolderMan::setDirtyProxy(bool value)
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *f, _folderMap.values()) {
|
|
|
|
if (f) {
|
2014-01-20 18:12:26 +04:00
|
|
|
f->setProxyDirty(value);
|
2015-03-25 14:25:18 +03:00
|
|
|
|
|
|
|
if (f->accountState() && f->accountState()->account()
|
2017-05-17 11:55:42 +03:00
|
|
|
&& f->accountState()->account()->networkAccessManager()) {
|
2015-10-05 07:21:19 +03:00
|
|
|
// Need to do this so we do not use the old determined system proxy
|
2015-03-25 14:25:18 +03:00
|
|
|
f->accountState()->account()->networkAccessManager()->setProxy(
|
2017-05-17 11:55:42 +03:00
|
|
|
QNetworkProxy(QNetworkProxy::DefaultProxy));
|
2015-03-25 14:25:18 +03:00
|
|
|
}
|
2014-01-20 18:12:26 +04:00
|
|
|
}
|
2013-10-14 18:11:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 20:29:50 +04:00
|
|
|
void FolderMan::setDirtyNetworkLimits()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *f, _folderMap.values()) {
|
2014-01-31 20:29:50 +04:00
|
|
|
// set only in busy folders. Otherwise they read the config anyway.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (f && f->isBusy()) {
|
2014-01-31 20:29:50 +04:00
|
|
|
f->setDirtyNetworkLimits();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-14 18:11:15 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
SyncResult FolderMan::accountStatus(const QList<Folder *> &folders)
|
2013-07-22 14:10:13 +04:00
|
|
|
{
|
2017-01-25 13:28:18 +03:00
|
|
|
SyncResult overallResult;
|
2013-07-22 14:10:13 +04:00
|
|
|
|
2013-12-20 18:13:33 +04:00
|
|
|
int cnt = folders.count();
|
|
|
|
|
|
|
|
// if one folder: show the state of the one folder.
|
2015-10-05 07:21:19 +03:00
|
|
|
// if more folders:
|
2013-12-20 18:13:33 +04:00
|
|
|
// if one of them has an error -> show error
|
|
|
|
// if one is paused, but others ok, show ok
|
|
|
|
// do not show "problem" in the tray
|
|
|
|
//
|
2017-05-17 11:55:42 +03:00
|
|
|
if (cnt == 1) {
|
2013-12-20 18:13:33 +04:00
|
|
|
Folder *folder = folders.at(0);
|
2017-05-17 11:55:42 +03:00
|
|
|
if (folder) {
|
|
|
|
if (folder->syncPaused()) {
|
2014-08-19 15:58:20 +04:00
|
|
|
overallResult.setStatus(SyncResult::Paused);
|
|
|
|
} else {
|
|
|
|
SyncResult::Status syncStatus = folder->syncResult().status();
|
|
|
|
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
switch (syncStatus) {
|
2014-08-19 15:58:20 +04:00
|
|
|
case SyncResult::Undefined:
|
|
|
|
overallResult.setStatus(SyncResult::Error);
|
|
|
|
break;
|
|
|
|
case SyncResult::NotYetStarted:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::NotYetStarted);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SyncPrepare:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::SyncPrepare);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SyncRunning:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::SyncRunning);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::Problem: // don't show the problem icon in tray.
|
|
|
|
case SyncResult::Success:
|
2017-05-17 11:55:42 +03:00
|
|
|
if (overallResult.status() == SyncResult::Undefined)
|
|
|
|
overallResult.setStatus(SyncResult::Success);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::Error:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::Error);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SetupError:
|
2017-05-17 11:55:42 +03:00
|
|
|
if (overallResult.status() != SyncResult::Error)
|
|
|
|
overallResult.setStatus(SyncResult::SetupError);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SyncAbortRequested:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::SyncAbortRequested);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::Paused:
|
2017-05-17 11:55:42 +03:00
|
|
|
overallResult.setStatus(SyncResult::Paused);
|
2014-08-19 15:58:20 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-12-20 18:13:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int errorsSeen = 0;
|
|
|
|
int goodSeen = 0;
|
2015-07-01 12:39:57 +03:00
|
|
|
int abortOrPausedSeen = 0;
|
2013-12-20 18:13:33 +04:00
|
|
|
int runSeen = 0;
|
|
|
|
int various = 0;
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *folder, folders) {
|
|
|
|
if (folder->syncPaused()) {
|
2015-07-01 12:39:57 +03:00
|
|
|
abortOrPausedSeen++;
|
2014-08-19 15:58:20 +04:00
|
|
|
} else {
|
|
|
|
SyncResult folderResult = folder->syncResult();
|
|
|
|
SyncResult::Status syncStatus = folderResult.status();
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
switch (syncStatus) {
|
2014-08-19 15:58:20 +04:00
|
|
|
case SyncResult::Undefined:
|
|
|
|
case SyncResult::NotYetStarted:
|
|
|
|
various++;
|
|
|
|
break;
|
2015-07-01 13:30:18 +03:00
|
|
|
case SyncResult::SyncPrepare:
|
2014-08-19 15:58:20 +04:00
|
|
|
case SyncResult::SyncRunning:
|
|
|
|
runSeen++;
|
|
|
|
break;
|
|
|
|
case SyncResult::Problem: // don't show the problem icon in tray.
|
|
|
|
case SyncResult::Success:
|
|
|
|
goodSeen++;
|
|
|
|
break;
|
|
|
|
case SyncResult::Error:
|
|
|
|
case SyncResult::SetupError:
|
|
|
|
errorsSeen++;
|
|
|
|
break;
|
|
|
|
case SyncResult::SyncAbortRequested:
|
|
|
|
case SyncResult::Paused:
|
2015-07-01 12:39:57 +03:00
|
|
|
abortOrPausedSeen++;
|
2014-08-19 15:58:20 +04:00
|
|
|
// no default case on purpose, check compiler warnings
|
|
|
|
}
|
2013-12-20 18:13:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool set = false;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (errorsSeen > 0) {
|
2013-12-20 18:13:33 +04:00
|
|
|
overallResult.setStatus(SyncResult::Error);
|
|
|
|
set = true;
|
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!set && abortOrPausedSeen > 0 && abortOrPausedSeen == cnt) {
|
2013-12-20 18:13:33 +04:00
|
|
|
// only if all folders are paused
|
|
|
|
overallResult.setStatus(SyncResult::Paused);
|
|
|
|
set = true;
|
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!set && runSeen > 0) {
|
2013-12-20 18:13:33 +04:00
|
|
|
overallResult.setStatus(SyncResult::SyncRunning);
|
|
|
|
set = true;
|
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!set && goodSeen > 0) {
|
2013-12-20 18:13:33 +04:00
|
|
|
overallResult.setStatus(SyncResult::Success);
|
|
|
|
set = true;
|
2013-07-22 14:10:13 +04:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 18:13:33 +04:00
|
|
|
|
2013-07-22 14:10:13 +04:00
|
|
|
return overallResult;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QString FolderMan::statusToString(SyncResult::Status syncStatus, bool paused) const
|
2013-07-22 14:10:13 +04:00
|
|
|
{
|
|
|
|
QString folderMessage;
|
2017-05-17 11:55:42 +03:00
|
|
|
switch (syncStatus) {
|
2013-07-22 14:10:13 +04:00
|
|
|
case SyncResult::Undefined:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Undefined State.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::NotYetStarted:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Waiting to start syncing.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SyncPrepare:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Preparing for sync.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::SyncRunning:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Sync is running.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::Success:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Last Sync was successful.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
|
|
|
case SyncResult::Error:
|
|
|
|
break;
|
2013-08-07 16:46:47 +04:00
|
|
|
case SyncResult::Problem:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Last Sync was successful, but with warnings on individual files.");
|
2013-08-07 16:46:47 +04:00
|
|
|
break;
|
2013-07-22 14:10:13 +04:00
|
|
|
case SyncResult::SetupError:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("Setup Error.");
|
2013-07-22 14:10:13 +04:00
|
|
|
break;
|
2013-10-03 18:21:54 +04:00
|
|
|
case SyncResult::SyncAbortRequested:
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("User Abort.");
|
2013-10-03 18:21:54 +04:00
|
|
|
break;
|
2013-12-20 18:13:33 +04:00
|
|
|
case SyncResult::Paused:
|
|
|
|
folderMessage = tr("Sync is paused.");
|
|
|
|
break;
|
2017-05-17 11:55:42 +03:00
|
|
|
// no default case on purpose, check compiler warnings
|
2013-07-22 14:10:13 +04:00
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (paused) {
|
2013-08-05 15:34:36 +04:00
|
|
|
// sync is disabled.
|
2017-05-17 11:55:42 +03:00
|
|
|
folderMessage = tr("%1 (Sync is paused)").arg(folderMessage);
|
2013-08-05 15:34:36 +04:00
|
|
|
}
|
2013-07-22 14:10:13 +04:00
|
|
|
return folderMessage;
|
2012-02-17 12:48:31 +04:00
|
|
|
}
|
2013-07-22 14:10:13 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QString FolderMan::checkPathValidityForNewFolder(const QString &path, const QUrl &serverUrl, bool forNewDirectory) const
|
2015-07-13 15:35:19 +03:00
|
|
|
{
|
2015-07-28 13:14:52 +03:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
return tr("No valid folder selected!");
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QFileInfo selFile(path);
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2015-07-28 13:14:52 +03:00
|
|
|
if (!selFile.exists()) {
|
2016-09-30 15:08:00 +03:00
|
|
|
return checkPathValidityForNewFolder(selFile.dir().path(), serverUrl, true);
|
2015-07-28 13:14:52 +03:00
|
|
|
}
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!selFile.isDir()) {
|
2015-09-07 09:51:22 +03:00
|
|
|
return tr("The selected path is not a folder!");
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!selFile.isWritable()) {
|
2015-07-13 15:35:19 +03:00
|
|
|
return tr("You have no permission to write to the selected folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the local directory isn't used yet in another ownCloud sync
|
2016-10-12 15:50:10 +03:00
|
|
|
Qt::CaseSensitivity cs = Qt::CaseSensitive;
|
2017-05-17 11:55:42 +03:00
|
|
|
if (Utility::fsCasePreserving()) {
|
2016-10-12 15:50:10 +03:00
|
|
|
cs = Qt::CaseInsensitive;
|
|
|
|
}
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
for (auto i = _folderMap.constBegin(); i != _folderMap.constEnd(); ++i) {
|
|
|
|
Folder *f = static_cast<Folder *>(i.value());
|
|
|
|
QString folderDir = QDir(f->path()).canonicalPath();
|
|
|
|
if (folderDir.isEmpty()) {
|
2015-07-13 15:35:19 +03:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!folderDir.endsWith(QLatin1Char('/'), cs))
|
|
|
|
folderDir.append(QLatin1Char('/'));
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
const QString folderDirClean = QDir::cleanPath(folderDir) + '/';
|
|
|
|
const QString userDirClean = QDir::cleanPath(path) + '/';
|
2016-10-12 19:16:53 +03:00
|
|
|
|
|
|
|
// folderDir follows sym links, path not.
|
2016-10-12 15:50:10 +03:00
|
|
|
bool differentPathes = !Utility::fileNamesEqual(QDir::cleanPath(folderDir), QDir::cleanPath(path));
|
2016-09-30 15:08:00 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!forNewDirectory && differentPathes && folderDirClean.startsWith(userDirClean, cs)) {
|
2015-09-08 14:37:57 +03:00
|
|
|
return tr("The local folder %1 already contains a folder used in a folder sync connection. "
|
|
|
|
"Please pick another one!")
|
2017-05-17 11:55:42 +03:00
|
|
|
.arg(QDir::toNativeSeparators(path));
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 19:16:53 +03:00
|
|
|
// QDir::cleanPath keeps links
|
|
|
|
// canonicalPath() remove symlinks and uses the symlink targets.
|
2017-05-17 11:55:42 +03:00
|
|
|
QString absCleanUserFolder = QDir::cleanPath(QDir(path).canonicalPath()) + '/';
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if ((forNewDirectory || differentPathes) && userDirClean.startsWith(folderDirClean, cs)) {
|
2015-09-08 14:37:57 +03:00
|
|
|
return tr("The local folder %1 is already contained in a folder used in a folder sync connection. "
|
|
|
|
"Please pick another one!")
|
2017-05-17 11:55:42 +03:00
|
|
|
.arg(QDir::toNativeSeparators(path));
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 19:16:53 +03:00
|
|
|
// both follow symlinks.
|
2017-05-17 11:55:42 +03:00
|
|
|
bool cleanUserEqualsCleanFolder = Utility::fileNamesEqual(absCleanUserFolder, folderDirClean);
|
|
|
|
if (differentPathes && absCleanUserFolder.startsWith(folderDirClean, cs) && !cleanUserEqualsCleanFolder) {
|
2015-09-08 14:37:57 +03:00
|
|
|
return tr("The local folder %1 is a symbolic link. "
|
|
|
|
"The link target is already contained in a folder used in a folder sync connection. "
|
|
|
|
"Please pick another one!")
|
2017-05-17 11:55:42 +03:00
|
|
|
.arg(QDir::toNativeSeparators(path));
|
2016-09-30 15:08:00 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (differentPathes && folderDirClean.startsWith(absCleanUserFolder, cs) && !cleanUserEqualsCleanFolder && !forNewDirectory) {
|
2016-10-07 17:23:13 +03:00
|
|
|
return tr("The local folder %1 contains a symbolic link. "
|
|
|
|
"The link target contains an already synced folder "
|
|
|
|
"Please pick another one!")
|
2017-05-17 11:55:42 +03:00
|
|
|
.arg(QDir::toNativeSeparators(path));
|
2016-10-07 17:23:13 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 19:16:53 +03:00
|
|
|
// if both pathes are equal, the server url needs to be different
|
|
|
|
// otherwise it would mean that a new connection from the same local folder
|
|
|
|
// to the same account is added which is not wanted. The account must differ.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (serverUrl.isValid() && Utility::fileNamesEqual(absCleanUserFolder, folderDir)) {
|
2016-09-30 15:08:00 +03:00
|
|
|
QUrl folderUrl = f->accountState()->account()->url();
|
|
|
|
QString user = f->accountState()->account()->credentials()->user();
|
|
|
|
folderUrl.setUserName(user);
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
if (serverUrl == folderUrl) {
|
2016-09-30 15:08:00 +03:00
|
|
|
return tr("There is already a sync from the server to this local folder. "
|
|
|
|
"Please pick another local folder!");
|
|
|
|
}
|
2015-07-13 15:35:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:28:32 +03:00
|
|
|
QString FolderMan::findGoodPathForNewSyncFolder(const QString &basePath, const QUrl &serverUrl) const
|
|
|
|
{
|
|
|
|
QString folder = basePath;
|
|
|
|
|
|
|
|
// If the parent folder is a sync folder or contained in one, we can't
|
|
|
|
// possibly find a valid sync folder inside it.
|
|
|
|
// Example: Someone syncs their home directory. Then ~/foobar is not
|
|
|
|
// going to be an acceptable sync folder path for any value of foobar.
|
|
|
|
QString parentFolder = QFileInfo(folder).dir().canonicalPath();
|
|
|
|
if (FolderMan::instance()->folderForPath(parentFolder)) {
|
|
|
|
// Any path with that parent is going to be unacceptable,
|
|
|
|
// so just keep it as-is.
|
|
|
|
return basePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
int attempt = 1;
|
|
|
|
forever {
|
|
|
|
const bool isGood =
|
2017-05-17 11:55:42 +03:00
|
|
|
!QFileInfo(folder).exists()
|
|
|
|
&& FolderMan::instance()->checkPathValidityForNewFolder(folder, serverUrl).isEmpty();
|
2017-03-20 16:28:32 +03:00
|
|
|
if (isGood) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count attempts and give up eventually
|
|
|
|
attempt++;
|
|
|
|
if (attempt > 100) {
|
|
|
|
return basePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
folder = basePath + QString::number(attempt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2015-08-10 12:03:57 +03:00
|
|
|
bool FolderMan::ignoreHiddenFiles() const
|
|
|
|
{
|
|
|
|
if (_folderMap.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return _folderMap.begin().value()->ignoreHiddenFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderMan::setIgnoreHiddenFiles(bool ignore)
|
|
|
|
{
|
|
|
|
// Note that the setting will revert to 'true' if all folders
|
|
|
|
// are deleted...
|
2017-05-17 11:55:42 +03:00
|
|
|
foreach (Folder *folder, _folderMap) {
|
2015-08-10 12:03:57 +03:00
|
|
|
folder->setIgnoreHiddenFiles(ignore);
|
|
|
|
folder->saveToSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QQueue<Folder *> FolderMan::scheduleQueue() const
|
2015-09-04 11:33:48 +03:00
|
|
|
{
|
2016-10-18 17:04:25 +03:00
|
|
|
return _scheduledFolders;
|
2015-09-04 11:33:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Folder *FolderMan::currentSyncFolder() const
|
|
|
|
{
|
|
|
|
return _currentSyncFolder;
|
|
|
|
}
|
|
|
|
|
2015-07-17 13:12:00 +03:00
|
|
|
void FolderMan::restartApplication()
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
if (Utility::isLinux()) {
|
2015-07-17 13:12:00 +03:00
|
|
|
// restart:
|
2017-03-30 14:46:20 +03:00
|
|
|
qCInfo(lcFolderMan) << "Restarting application NOW, PID" << qApp->applicationPid() << "is ending.";
|
2015-07-17 13:12:00 +03:00
|
|
|
qApp->quit();
|
|
|
|
QStringList args = qApp->arguments();
|
|
|
|
QString prg = args.takeFirst();
|
|
|
|
|
|
|
|
QProcess::startDetached(prg, args);
|
|
|
|
} else {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcFolderMan) << "On this platform we do not restart.";
|
2015-07-17 13:12:00 +03:00
|
|
|
}
|
|
|
|
}
|
2015-07-13 15:35:19 +03:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|