From 7230fa6b4fb0d077bc82814074aeb853ed45345f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 5 Dec 2017 16:54:02 +0100 Subject: [PATCH 1/4] SyncOptions: move to its own file It does not really belong in the discoveryphase.h as it is used also for propagator option. Also use C++11 style member initializer --- src/libsync/discoveryphase.h | 47 +----------------------- src/libsync/owncloudpropagator.h | 2 +- src/libsync/syncoptions.h | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 src/libsync/syncoptions.h diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index eea33ad52c..222f4a999d 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -24,6 +24,7 @@ #include #include #include +#include "syncoptions.h" namespace OCC { @@ -35,52 +36,6 @@ class Account; * if the files are new, or changed. */ -struct SyncOptions -{ - SyncOptions() - : _newBigFolderSizeLimit(-1) - , _confirmExternalStorage(false) - , _initialChunkSize(10 * 1000 * 1000) // 10 MB - , _minChunkSize(1 * 1000 * 1000) // 1 MB - , _maxChunkSize(100 * 1000 * 1000) // 100 MB - , _targetChunkUploadDuration(60 * 1000) // 1 minute - , _parallelNetworkJobs(true) - { - } - - /** Maximum size (in Bytes) a folder can have without asking for confirmation. - * -1 means infinite */ - qint64 _newBigFolderSizeLimit; - - /** If a confirmation should be asked for external storages */ - bool _confirmExternalStorage; - - /** The initial un-adjusted chunk size in bytes for chunked uploads, both - * for old and new chunking algorithm, which classifies the item to be chunked - * - * In chunkingNG, when dynamic chunk size adjustments are done, this is the - * starting value and is then gradually adjusted within the - * minChunkSize / maxChunkSize bounds. - */ - quint64 _initialChunkSize; - - /** The minimum chunk size in bytes for chunked uploads */ - quint64 _minChunkSize; - - /** The maximum chunk size in bytes for chunked uploads */ - quint64 _maxChunkSize; - - /** The target duration of chunk uploads for dynamic chunk sizing. - * - * Set to 0 it will disable dynamic chunk sizing. - */ - quint64 _targetChunkUploadDuration; - - /** Whether parallel network jobs are allowed. */ - bool _parallelNetworkJobs; -}; - - struct DiscoveryDirectoryResult { QString path; diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index 9655e1ac49..efc7c01dda 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -30,7 +30,7 @@ #include "common/syncjournaldb.h" #include "bandwidthmanager.h" #include "accountfwd.h" -#include "discoveryphase.h" +#include "syncoptions.h" namespace OCC { diff --git a/src/libsync/syncoptions.h b/src/libsync/syncoptions.h new file mode 100644 index 0000000000..f6565584cd --- /dev/null +++ b/src/libsync/syncoptions.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) by Olivier Goffart + * + * 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. + */ + +#pragma once + +#include "owncloudlib.h" +#include + + +namespace OCC { + +/** + * Value class containing the options given to the sync engine + */ +struct SyncOptions +{ + /** Maximum size (in Bytes) a folder can have without asking for confirmation. + * -1 means infinite */ + qint64 _newBigFolderSizeLimit = -1; + + /** If a confirmation should be asked for external storages */ + bool _confirmExternalStorage = false; + + /** The initial un-adjusted chunk size in bytes for chunked uploads, both + * for old and new chunking algorithm, which classifies the item to be chunked + * + * In chunkingNG, when dynamic chunk size adjustments are done, this is the + * starting value and is then gradually adjusted within the + * minChunkSize / maxChunkSize bounds. + */ + quint64 _initialChunkSize = 10 * 1000 * 1000; // 10MB + + /** The minimum chunk size in bytes for chunked uploads */ + quint64 _minChunkSize = 1 * 1000 * 1000; // 1MB + + /** The maximum chunk size in bytes for chunked uploads */ + quint64 _maxChunkSize = 100 * 1000 * 1000; // 100MB + + /** The target duration of chunk uploads for dynamic chunk sizing. + * + * Set to 0 it will disable dynamic chunk sizing. + */ + quint64 _targetChunkUploadDuration = 60 * 1000; // 1 minute + + /** Whether parallel network jobs are allowed. */ + bool _parallelNetworkJobs = true; +}; + + +} From ac844a2a45af5579c4013a02f6efc93fa83dc79f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 5 Dec 2017 18:11:09 +0100 Subject: [PATCH 2/4] AbstractNetworkJob: move the httpTimeout from the propagator to the network job Remove one dependency from the config file for the sync engine. Part of issue #6213 --- src/gui/application.cpp | 6 +++++- src/libsync/abstractnetworkjob.cpp | 5 ++++- src/libsync/abstractnetworkjob.h | 4 ++++ src/libsync/owncloudpropagator.cpp | 14 -------------- src/libsync/owncloudpropagator.h | 3 --- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 88a2c5c084..1f8b53be89 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -139,6 +139,11 @@ Application::Application(int &argc, char **argv) setupLogging(); setupTranslations(); + // The timeout is initialized with an environment variable, if not, override with the value from the config + ConfigFile cfg; + if (!AbstractNetworkJob::httpTimeout) + AbstractNetworkJob::httpTimeout = cfg.timeout(); + _folderManager.reset(new FolderMan); connect(this, &SharedTools::QtSingleApplication::messageReceived, this, &Application::slotParseMessage); @@ -166,7 +171,6 @@ Application::Application(int &argc, char **argv) setQuitOnLastWindowClosed(false); - ConfigFile cfg; _theme->setSystrayUseMonoIcons(cfg.monoIcons()); connect(_theme, &Theme::systrayUseMonoIconsChanged, this, &Application::slotUseMonoIconsChanged); diff --git a/src/libsync/abstractnetworkjob.cpp b/src/libsync/abstractnetworkjob.cpp index 78d5b9ab6b..0149bec425 100644 --- a/src/libsync/abstractnetworkjob.cpp +++ b/src/libsync/abstractnetworkjob.cpp @@ -40,6 +40,9 @@ namespace OCC { Q_LOGGING_CATEGORY(lcNetworkJob, "sync.networkjob", QtInfoMsg) +// If not set, it is overwritten by the Application constructor with the value from the config +int AbstractNetworkJob::httpTimeout = qEnvironmentVariableIntValue("OWNCLOUD_TIMEOUT"); + AbstractNetworkJob::AbstractNetworkJob(AccountPtr account, const QString &path, QObject *parent) : QObject(parent) , _timedout(false) @@ -51,7 +54,7 @@ AbstractNetworkJob::AbstractNetworkJob(AccountPtr account, const QString &path, , _redirectCount(0) { _timer.setSingleShot(true); - _timer.setInterval(OwncloudPropagator::httpTimeout() * 1000); // default to 5 minutes. + _timer.setInterval((httpTimeout ? httpTimeout : 300) * 1000); // default to 5 minutes. connect(&_timer, &QTimer::timeout, this, &AbstractNetworkJob::slotTimeout); connect(this, &AbstractNetworkJob::networkActivity, this, &AbstractNetworkJob::resetTimeout); diff --git a/src/libsync/abstractnetworkjob.h b/src/libsync/abstractnetworkjob.h index ec9a31addc..b49f722823 100644 --- a/src/libsync/abstractnetworkjob.h +++ b/src/libsync/abstractnetworkjob.h @@ -88,6 +88,10 @@ public: */ QString errorStringParsingBody(QByteArray *body = 0); + /** static variable the HTTP timeout (in seconds). If set to 0, the default will be used + */ + static int httpTimeout; + public slots: void setTimeout(qint64 msec); void resetTimeout(); diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index d90ae8af77..e1d081141a 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -22,7 +22,6 @@ #include "propagateremotemove.h" #include "propagateremotemkdir.h" #include "propagatorjobs.h" -#include "configfile.h" #include "common/utility.h" #include "account.h" #include "common/asserts.h" @@ -554,19 +553,6 @@ bool OwncloudPropagator::isInSharedDirectory(const QString &file) return re; } -int OwncloudPropagator::httpTimeout() -{ - static int timeout = 0; - if (!timeout) { - timeout = qgetenv("OWNCLOUD_TIMEOUT").toUInt(); - if (timeout == 0) { - ConfigFile cfg; - timeout = cfg.timeout(); - } - } - return timeout; -} - bool OwncloudPropagator::localFileNameClash(const QString &relFile) { bool re = false; diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index efc7c01dda..062b3825e5 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -464,9 +464,6 @@ public: } } - // timeout in seconds - static int httpTimeout(); - AccountPtr account() const; enum DiskSpaceResult { From e0a14cac5b03ea41303e1602b79b51fec1f5c1de Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 6 Dec 2017 15:29:07 +0100 Subject: [PATCH 3/4] ConfigFile: use QStandardPaths::AppConfigLocation for the config file Also use appName instead of appNameGui in order to compute the path Issue: #2245 The reason is to respect the XDG spec on Unix (#1601) and might help on windows roaming profiles (#684) --- doc/autoupdate.rst | 2 +- doc/conffile.rst | 6 +++--- src/gui/application.cpp | 21 ++++++++++++++++++++- src/libsync/configfile.cpp | 16 ++++------------ src/libsync/configfile.h | 1 - 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/doc/autoupdate.rst b/doc/autoupdate.rst index ad0ff03408..e581a70aec 100644 --- a/doc/autoupdate.rst +++ b/doc/autoupdate.rst @@ -119,7 +119,7 @@ Preventing Automatic Updates in Linux Environments Because the Linux client does not provide automatic updating functionality, there is no need to remove the automatic-update check. However, if you want to disable it edit your desktop -client configuration file, ``$HOME/.local/share/data/ownCloud/owncloud.cfg``. +client configuration file, ``$HOME/.config/ownCloud/owncloud.cfg``. Add this line to the [General] section:: skipUpdateCheck=true diff --git a/doc/conffile.rst b/doc/conffile.rst index 3fdcc179b7..dda2bd68b0 100644 --- a/doc/conffile.rst +++ b/doc/conffile.rst @@ -1,13 +1,13 @@ The ownCloud Client reads a configuration file. You can locate this configuration file as follows: On Linux distributions: - ``$HOME/.local/share/data/ownCloud/owncloud.cfg`` + ``$HOME/.config/ownCloud/owncloud.cfg`` On Microsoft Windows systems: - ``%LOCALAPPDATA%\ownCloud\owncloud.cfg`` + ``%APPDATA%\ownCloud\owncloud.cfg`` On MAC OS X systems: - ``$HOME/Library/Application Support/ownCloud/owncloud.cfg`` + ``$HOME/Library/Preferences/ownCloud/owncloud.cfg`` The configuration file contains settings using the Microsoft Windows .ini file diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 1f8b53be89..715e81e9a5 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -119,10 +119,29 @@ Application::Application(int &argc, char **argv) // TODO: Can't set this without breaking current config paths // setOrganizationName(QLatin1String(APPLICATION_VENDOR)); setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN)); - setApplicationName(_theme->appNameGUI()); + setApplicationName(_theme->appName()); setWindowIcon(_theme->applicationIcon()); setAttribute(Qt::AA_UseHighDpiPixmaps, true); + auto confDir = ConfigFile().configPath(); + if (!QFileInfo(confDir).exists()) { + // Migrate from version <= 2.4 + setApplicationName(_theme->appNameGUI()); + QString oldDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + setApplicationName(_theme->appName()); + if (QFileInfo(oldDir).isDir()) { + qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir; + if (!QFile::rename(oldDir, confDir)) { + qCWarning(lcApplication) << "Failed to move the old config file to its new location (" << oldDir << "to" << confDir << ")"; + } else { +#ifndef Q_OS_WIN + // Create a symbolic link so a downgrade of the client would still find the config. + QFile::link(confDir, oldDir); +#endif + } + } + } + parseOptions(arguments()); //no need to waste time; if (_helpOnly || _versionOnly) diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index d988159206..a564bff25f 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -26,7 +26,6 @@ #ifndef TOKEN_AUTH_ONLY #include #include -#include #endif #include @@ -36,6 +35,7 @@ #include #include #include +#include #define DEFAULT_REMOTE_POLL_INTERVAL 30000 // default remote poll time in milliseconds #define DEFAULT_FULL_LOCAL_DISCOVERY_INTERVAL (60 * 60 * 1000) // 1 hour @@ -252,13 +252,11 @@ QVariant ConfigFile::getPolicySetting(const QString &setting, const QVariant &de QString ConfigFile::configPath() const { -#ifndef TOKEN_AUTH_ONLY if (_confDir.isEmpty()) { - // Qt 5's QStandardPaths::writableLocation gives us wrong results (without /data/), - // so we'll have to use the deprecated version for now - _confDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + // On Unix, use the AppConfigLocation for the settings, that's configurable with the XDG_CONFIG_HOME env variable. + // On Windows, use AppDataLocation, that's where the roaming data is and where we should store the config file + _confDir = QStandardPaths::writableLocation(Utility::isWindows() ? QStandardPaths::AppDataLocation : QStandardPaths::AppConfigLocation); } -#endif QString dir = _confDir; if (!dir.endsWith(QLatin1Char('/'))) @@ -266,12 +264,6 @@ QString ConfigFile::configPath() const return dir; } -QString ConfigFile::configPathWithAppName() const -{ - //HACK - return QFileInfo(configFile()).dir().absolutePath().append("/"); -} - static const QLatin1String exclFile("sync-exclude.lst"); QString ConfigFile::excludeFile(Scope scope) const diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index f1bcf74926..bd33fdc04e 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -43,7 +43,6 @@ public: SystemScope }; QString configPath() const; - QString configPathWithAppName() const; QString configFile() const; QString excludeFile(Scope scope) const; static QString excludeFileFromSystem(); // doesn't access config dir From 4581d708ff6a218d790ce2b7c1e6e21ae6231778 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 6 Dec 2017 15:45:17 +0100 Subject: [PATCH 4/4] Account: remove dependency with ConfigFile Part of #6213 --- src/cmd/simplesslerrorhandler.cpp | 1 - src/gui/application.cpp | 1 + src/libsync/account.cpp | 5 ++--- src/libsync/capabilities.cpp | 2 -- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cmd/simplesslerrorhandler.cpp b/src/cmd/simplesslerrorhandler.cpp index 4374385071..b25e9958fb 100644 --- a/src/cmd/simplesslerrorhandler.cpp +++ b/src/cmd/simplesslerrorhandler.cpp @@ -11,7 +11,6 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ -#include "configfile.h" #include "common/utility.h" #include "account.h" #include "simplesslerrorhandler.h" diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 715e81e9a5..8f4b3f1ba4 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -51,6 +51,7 @@ #include #include #include +#include class QSocket; diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 674ab34f90..7907ea530d 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -15,7 +15,6 @@ #include "account.h" #include "cookiejar.h" #include "networkjobs.h" -#include "configfile.h" #include "accessmanager.h" #include "creds/abstractcredentials.h" #include "capabilities.h" @@ -33,6 +32,7 @@ #include #include #include +#include namespace OCC { @@ -206,8 +206,7 @@ void Account::lendCookieJarTo(QNetworkAccessManager *guest) QString Account::cookieJarPath() { - ConfigFile cfg; - return cfg.configPath() + "/cookies" + id() + ".db"; + return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/cookies" + id() + ".db"; } void Account::resetNetworkAccessManager() diff --git a/src/libsync/capabilities.cpp b/src/libsync/capabilities.cpp index fcf71b7e9a..3334103733 100644 --- a/src/libsync/capabilities.cpp +++ b/src/libsync/capabilities.cpp @@ -14,8 +14,6 @@ #include "capabilities.h" -#include "configfile.h" - #include namespace OCC {