namespace OCC {
-
Folder::Folder(const FolderDefinition& definition,
AccountState* accountState,
QObject* parent)
_definition.ignoreHiddenFiles = ignore;
}
-QString Folder::cleanPath()
+QString Folder::cleanPath() const
{
QString cleanedPath = QDir::cleanPath(_canonicalLocalPath);
void Folder::saveToSettings() const
{
+ // Remove first to make sure we don't get duplicates
+ removeFromSettings();
+
auto settings = _accountState->settings();
- settings->beginGroup(QLatin1String("Folders"));
+
+ // The folder is saved to backwards-compatible "Folders"
+ // section only if it has the migrate flag set (i.e. was in
+ // there before) or if the folder is the only one for the
+ // given target path.
+ // This ensures that older clients will not read a configuration
+ // where two folders for different accounts point at the same
+ // local folders.
+ bool oneAccountOnly = true;
+ foreach (Folder* other, FolderMan::instance()->map()) {
+ if (other != this && other->cleanPath() == this->cleanPath()) {
+ oneAccountOnly = false;
+ break;
+ }
+ }
+
+ bool inFolders = _journal.mayMigrateDbLocation() || oneAccountOnly;
+
+ if (inFolders) {
+ settings->beginGroup(QLatin1String("Folders"));
+ } else {
+ settings->beginGroup(QLatin1String("Multifolders"));
+ }
FolderDefinition::save(*settings, _definition);
settings->sync();
void Folder::removeFromSettings() const
{
- auto settings = _accountState->settings();
+ auto settings = _accountState->settings();
settings->beginGroup(QLatin1String("Folders"));
settings->remove(FolderMan::escapeAlias(_definition.alias));
+ settings->endGroup();
+ settings->beginGroup(QLatin1String("Multifolders"));
+ settings->remove(FolderMan::escapeAlias(_definition.alias));
}
bool Folder::isFileExcludedAbsolute(const QString& fullPath) const
/**
* wrapper for QDir::cleanPath("Z:\\"), which returns "Z:\\", but we need "Z:" instead
*/
- QString cleanPath();
+ QString cleanPath() const;
/**
* remote folder path
continue;
}
settings->beginGroup(id);
+
settings->beginGroup(QLatin1String("Folders"));
- foreach (const auto& folderAlias, settings->childGroups()) {
- FolderDefinition folderDefinition;
- if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) {
- Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
- if (f) {
- scheduleFolder(f);
- emit folderSyncStateChange(f);
- }
- }
- }
- settings->endGroup(); // Folders
+ 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();
+
settings->endGroup(); // <account>
}
return _folderMap.size();
}
+void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool mayMigrateOldDb)
+{
+ foreach (const auto& folderAlias, settings.childGroups()) {
+ FolderDefinition folderDefinition;
+ if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
+ Folder* f = addFolderInternal(std::move(folderDefinition), account.data());
+ if (f) {
+ f->journalDb()->setMayMigrateDbLocation(mayMigrateOldDb);
+ scheduleFolder(f);
+ emit folderSyncStateChange(f);
+ }
+ }
+ }
+}
+
int FolderMan::setupFoldersMigration()
{
ConfigFile cfg;
// restarts the application (Linux only)
void restartApplication();
+ void setupFoldersHelper(QSettings& settings, AccountStatePtr account, bool mayMigrateOldDb);
+
QSet<Folder*> _disabledFolders;
Folder::Map _folderMap;
QString _folderConfigPath;
namespace OCC {
SyncJournalDb::SyncJournalDb( QObject *parent) :
- QObject(parent), _transaction(0)
+ QObject(parent),
+ _transaction(0),
+ _mayMigrateDbLocation(false)
{
}
_dbFile.append(".db");
}
+bool SyncJournalDb::mayMigrateDbLocation() const
+{
+ return _mayMigrateDbLocation;
+}
+
+void SyncJournalDb::setMayMigrateDbLocation(bool migrate)
+{
+ _mayMigrateDbLocation = migrate;
+}
+
#ifndef NDEBUG
void SyncJournalDb::setDatabaseFilePath( const QString& dbFile)
{
const QString dir = _dbFile.left( _dbFile.lastIndexOf(QChar('/')) );
const QString oldDbName = dir + QLatin1String("/.csync_journal.db");
- bool migrateOldDb = FileSystem::fileExists(oldDbName);
+ bool migrateOldDb = _mayMigrateDbLocation && FileSystem::fileExists(oldDbName);
// Whenever there is an old db file, migrate it to the new db path.
// This is done to make switching from older versions to newer versions
#endif
void setAccountParameterForFilePath(const QString& localPath, const QUrl &remoteUrl, const QString& remotePath );
+ bool mayMigrateDbLocation() const;
+ void setMayMigrateDbLocation(bool migrate);
+
static qint64 getPHash(const QString& );
void updateErrorBlacklistEntry( const SyncJournalErrorBlacklistRecord& item );
* that would write the etag and would void the purpose of avoidReadFromDbOnNextSync
*/
QList<QString> _avoidReadFromDbOnNextSyncFilter;
+
+ /**
+ * Whether to check old journal path (csync_journal.db) and move the file
+ * to its new location, if it exists.
+ */
+ bool _mayMigrateDbLocation;
};
bool OWNCLOUDSYNC_EXPORT