"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/gui/folderman.cpp" between
ownCloud-2.9.0.5150.tar.xz and ownCloud-2.9.1.5500.tar.xz

About: ownCloud Client (formerly "mirall") is a tool to synchronize files from ownCloud Server with your desktop client. It uses OCSync as its syncing backend.

folderman.cpp  (ownCloud-2.9.0.5150.tar.xz):folderman.cpp  (ownCloud-2.9.1.5500.tar.xz)
skipping to change at line 40 skipping to change at line 40
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#endif #endif
#include <QMessageBox> #include <QMessageBox>
#include <QtCore> #include <QtCore>
#include <QMutableSetIterator> #include <QMutableSetIterator>
#include <QSet> #include <QSet>
#include <QNetworkProxy> #include <QNetworkProxy>
namespace { namespace {
const char versionC[] = "version"; /*
const int maxFoldersVersion = 1; * [Accounts]
* 0\version=1
*/
auto versionC()
{
return QStringLiteral("version");
}
/*
* Folders with a version > maxFoldersVersion will be removed
* After the user was prompted for consent.
*/
constexpr int maxFoldersVersion = 1;
int numberOfSyncJournals(const QString &path) int numberOfSyncJournals(const QString &path)
{ {
return QDir(path).entryList({ QStringLiteral(".sync_*.db"), QStringLiteral(" ._sync_*.db") }, QDir::Hidden | QDir::Files).size(); return QDir(path).entryList({ QStringLiteral(".sync_*.db"), QStringLiteral(" ._sync_*.db") }, QDir::Hidden | QDir::Files).size();
} }
QString makeLegacyDbName(const OCC::FolderDefinition &def, const OCC::AccountPtr
&account)
{
// ensure https://demo.owncloud.org/ matches https://demo.owncloud.org
// the empty path was the legacy formating before 2.9
auto legacyUrl = account->url();
if (legacyUrl.path() == QLatin1String("/")) {
legacyUrl.setPath(QString());
}
const QString key = QStringLiteral("%1@%2:%3").arg(account->credentials()->u
ser(), legacyUrl.toString(), def.targetPath);
return OCC::SyncJournalDb::makeDbName(def.localPath, QString::fromUtf8(QCryp
tographicHash::hash(key.toUtf8(), QCryptographicHash::Md5).left(6).toHex()));
}
} }
namespace OCC { namespace OCC {
Q_LOGGING_CATEGORY(lcFolderMan, "gui.folder.manager", QtInfoMsg) Q_LOGGING_CATEGORY(lcFolderMan, "gui.folder.manager", QtInfoMsg)
void TrayOverallStatusResult::addResult(Folder *f) void TrayOverallStatusResult::addResult(Folder *f)
{ {
_overallStatus._numNewConflictItems += f->syncResult()._numNewConflictItems; _overallStatus._numNewConflictItems += f->syncResult()._numNewConflictItems;
_overallStatus._numErrorItems += f->syncResult()._numErrorItems; _overallStatus._numErrorItems += f->syncResult()._numErrorItems;
_overallStatus._numBlacklistErrors += f->syncResult()._numBlacklistErrors; _overallStatus._numBlacklistErrors += f->syncResult()._numBlacklistErrors;
skipping to change at line 289 skipping to change at line 312
qCInfo(lcFolderMan) << "Folder" << folderAlias << "is too new, ignor ing"; qCInfo(lcFolderMan) << "Folder" << folderAlias << "is too new, ignor ing";
_additionalBlockedFolderAliases.insert(folderAlias); _additionalBlockedFolderAliases.insert(folderAlias);
settings.endGroup(); settings.endGroup();
continue; continue;
} }
settings.endGroup(); settings.endGroup();
FolderDefinition folderDefinition; FolderDefinition folderDefinition;
settings.beginGroup(folderAlias); settings.beginGroup(folderAlias);
if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) { if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
auto defaultJournalPath = folderDefinition.defaultJournalPath(accoun const auto defaultJournalPath = [&account, folderDefinition] {
t->account()); // if we would have booth the 2.9.0 file name and the lagacy fil
e
// with the md5 infix we prefer the 2.9.0 version
const QDir info(folderDefinition.localPath);
const QString defaultPath = SyncJournalDb::makeDbName(folderDefi
nition.localPath);
if (info.exists(defaultPath)) {
return defaultPath;
}
// 2.6
QString legacyPath = makeLegacyDbName(folderDefinition, account-
>account());
if (info.exists(legacyPath)) {
return legacyPath;
}
// pre 2.6
legacyPath.replace(QLatin1String(".sync_"), QLatin1String("._syn
c_"));
if (info.exists(legacyPath)) {
return legacyPath;
}
return defaultPath;
}();
// Migration: Old settings don't have journalPath // Migration: Old settings don't have journalPath
if (folderDefinition.journalPath.isEmpty()) { if (folderDefinition.journalPath.isEmpty()) {
folderDefinition.journalPath = defaultJournalPath; folderDefinition.journalPath = defaultJournalPath;
} }
// Migration: ._ files sometimes can't be created. // Migration: ._ files sometimes can't be created.
// So if the configured journalPath has a dot-underscore ("._sync_*. db") // So if the configured journalPath has a dot-underscore ("._sync_*. db")
// but the current default doesn't have the underscore, switch to th e // but the current default doesn't have the underscore, switch to th e
// new default if no db exists yet. // new default if no db exists yet.
if (folderDefinition.journalPath.startsWith("._sync_") if (folderDefinition.journalPath.startsWith("._sync_")
&& defaultJournalPath.startsWith(".sync_") && defaultJournalPath.startsWith(".sync_")
&& !QFile::exists(folderDefinition.absoluteJournalPath())) { && !QFile::exists(folderDefinition.absoluteJournalPath())) {
folderDefinition.journalPath = defaultJournalPath; folderDefinition.journalPath = defaultJournalPath;
} }
// Migration: If an old db is found, move it to the new name. // Migration: If an old .csync_journal.db is found, move it to the n ew name.
if (backwardsCompatible) { if (backwardsCompatible) {
SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folder Definition.absoluteJournalPath()); SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folder Definition.absoluteJournalPath());
} }
auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode);
if (!vfs) { if (!vfs) {
// TODO: Must do better error handling // TODO: Must do better error handling
qFatal("Could not load plugin"); qFatal("Could not load plugin");
} }
Folder *f = addFolderInternal(std::move(folderDefinition), account.d ata(), std::move(vfs)); Folder *f = addFolderInternal(std::move(folderDefinition), account.d ata(), std::move(vfs));
if (f) { if (f) {
// Migrate the old "usePlaceholders" setting to the root folder pin state // Migrate the old "usePlaceholders" setting to the root folder pin state
if (settings.value(QLatin1String(versionC), 1).toInt() == 1 if (settings.value(versionC(), 1).toInt() == 1
&& settings.value(QLatin1String("usePlaceholders"), false).t oBool()) { && settings.value(QLatin1String("usePlaceholders"), false).t oBool()) {
qCInfo(lcFolderMan) << "Migrate: From usePlaceholders to Pin State::OnlineOnly"; qCInfo(lcFolderMan) << "Migrate: From usePlaceholders to Pin State::OnlineOnly";
f->setRootPinState(PinState::OnlineOnly); f->setRootPinState(PinState::OnlineOnly);
} }
// Migration: Mark folders that shall be saved in a backwards-co mpatible way // Migration: Mark folders that shall be saved in a backwards-co mpatible way
if (backwardsCompatible) if (backwardsCompatible)
f->setSaveBackwardsCompatible(true); f->setSaveBackwardsCompatible(true);
if (foldersWithPlaceholders) if (foldersWithPlaceholders)
f->setSaveInFoldersWithPlaceholders(); f->setSaveInFoldersWithPlaceholders();
// save possible changes from the migration
f->saveToSettings();
scheduleFolder(f); scheduleFolder(f);
emit folderSyncStateChange(f); emit folderSyncStateChange(f);
} }
} }
settings.endGroup(); settings.endGroup();
} }
} }
int FolderMan::setupFoldersMigration() int FolderMan::setupFoldersMigration()
{ {
skipping to change at line 373 skipping to change at line 418
// return the number of valid folders. // return the number of valid folders.
return _folderMap.size(); return _folderMap.size();
} }
void FolderMan::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringLi st *ignoreKeys) void FolderMan::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringLi st *ignoreKeys)
{ {
auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts")); auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));
auto processSubgroup = [&](const QString &name) { auto processSubgroup = [&](const QString &name) {
settings->beginGroup(name); settings->beginGroup(name);
const int foldersVersion = settings->value(QLatin1String(versionC), 1).t oInt(); const int foldersVersion = settings->value(versionC(), 1).toInt();
if (foldersVersion <= maxFoldersVersion) { if (foldersVersion <= maxFoldersVersion) {
const auto &childGroups = settings->childGroups(); const auto &childGroups = settings->childGroups();
for (const auto &folderAlias : childGroups) { for (const auto &folderAlias : childGroups) {
settings->beginGroup(folderAlias); settings->beginGroup(folderAlias);
const int folderVersion = settings->value(QLatin1String(versionC ), 1).toInt(); const int folderVersion = settings->value(versionC(), 1).toInt() ;
if (folderVersion > FolderDefinition::maxSettingsVersion()) { if (folderVersion > FolderDefinition::maxSettingsVersion()) {
ignoreKeys->append(settings->group()); ignoreKeys->append(settings->group());
} }
settings->endGroup(); settings->endGroup();
} }
} else { } else {
deleteKeys->append(settings->group()); deleteKeys->append(settings->group());
} }
settings->endGroup(); settings->endGroup();
}; };
skipping to change at line 487 skipping to change at line 532
// WARNING: Do not remove this code, it is used for predefined/automated deploym ents (2016) // WARNING: Do not remove this code, it is used for predefined/automated deploym ents (2016)
Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat e *accountState) Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat e *accountState)
{ {
Folder *folder = nullptr; Folder *folder = nullptr;
qCInfo(lcFolderMan) << " ` -> setting up:" << file; qCInfo(lcFolderMan) << " ` -> setting up:" << file;
QString escapedAlias(file); QString escapedAlias(file);
// check the unescaped variant (for the case when the filename comes out // check the unescaped variant (for the case when the filename comes out
// of the directory listing). If the file does not exist, escape the // of the directory listing). If the file does not exist, escape the
// file and try again. // file and try again.
#ifdef Q_OS_WIN
Utility::NtfsPermissionLookupRAII ntfs_perm;
#endif
QFileInfo cfgFile(_folderConfigPath, file); QFileInfo cfgFile(_folderConfigPath, file);
if (!cfgFile.exists()) { if (!cfgFile.exists()) {
// try the escaped variant. // try the escaped variant.
escapedAlias = escapeAlias(file); escapedAlias = escapeAlias(file);
cfgFile.setFile(_folderConfigPath, escapedAlias); cfgFile.setFile(_folderConfigPath, escapedAlias);
} }
if (!cfgFile.isReadable()) { if (!cfgFile.isReadable()) {
qCWarning(lcFolderMan) << "Cannot read folder definition for alias " << cfgFile.filePath(); qCWarning(lcFolderMan) << "Cannot read folder definition for alias " << cfgFile.filePath();
return folder; return folder;
skipping to change at line 619 skipping to change at line 668
{ {
_lockWatcher->addFile(path, mode); _lockWatcher->addFile(path, mode);
} }
/* /*
* if a folder wants to be synced, it calls this slot and is added * 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. * to the queue. The slot to actually start a sync is called afterwards.
*/ */
void FolderMan::scheduleFolder(Folder *f) void FolderMan::scheduleFolder(Folder *f)
{ {
if (!f) { if (!OC_ENSURE(f)) {
qCCritical(lcFolderMan) << "slotScheduleSync called with null folder";
return; return;
} }
auto alias = f->alias(); auto alias = f->alias();
qCInfo(lcFolderMan) << "Schedule folder " << alias << " to sync!"; qCInfo(lcFolderMan) << "Schedule folder " << alias << " to sync!";
if (!_scheduledFolders.contains(f)) { if (!_scheduledFolders.contains(f)) {
if (!f->canSync()) { if (!f->canSync()) {
qCInfo(lcFolderMan) << "Folder is not ready to sync, not scheduled!" ; qCInfo(lcFolderMan) << "Folder is not ready to sync, not scheduled!" ;
_socketApi->slotUpdateFolderView(f); _socketApi->slotUpdateFolderView(f);
skipping to change at line 842 skipping to change at line 890
emit scheduleQueueChanged(); emit scheduleQueueChanged();
// Start syncing this folder! // Start syncing this folder!
if (folder) { if (folder) {
// Safe to call several times, and necessary to try again if // Safe to call several times, and necessary to try again if
// the folder path didn't exist previously. // the folder path didn't exist previously.
folder->registerFolderWatcher(); folder->registerFolderWatcher();
registerFolderWithSocketApi(folder); registerFolderWithSocketApi(folder);
_currentSyncFolder = folder; _currentSyncFolder = folder;
folder->startSync(QStringList()); folder->startSync();
} }
} }
void FolderMan::slotEtagPollTimerTimeout() void FolderMan::slotEtagPollTimerTimeout()
{ {
for (auto *f : qAsConst(_folderMap)) { for (auto *f : qAsConst(_folderMap)) {
if (!f) { if (!f) {
continue; continue;
} }
if (_scheduledFolders.contains(f)) { if (_scheduledFolders.contains(f)) {
skipping to change at line 1014 skipping to change at line 1062
_currentSyncFolder = nullptr; _currentSyncFolder = nullptr;
} }
if (!isAnySyncRunning()) if (!isAnySyncRunning())
startScheduledSyncSoon(); startScheduledSyncSoon();
} }
Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition) Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition)
{ {
// Choose a db filename // Choose a db filename
auto definition = folderDefinition; auto definition = folderDefinition;
definition.journalPath = definition.defaultJournalPath(accountState->account ()); definition.journalPath = SyncJournalDb::makeDbName(folderDefinition.localPat h);
if (!ensureJournalGone(definition.absoluteJournalPath())) { if (!ensureJournalGone(definition.absoluteJournalPath())) {
return nullptr; return nullptr;
} }
auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode);
if (!vfs) { if (!vfs) {
qCWarning(lcFolderMan) << "Could not load plugin for mode" << folderDefi nition.virtualFilesMode; qCWarning(lcFolderMan) << "Could not load plugin for mode" << folderDefi nition.virtualFilesMode;
return nullptr; return nullptr;
} }
skipping to change at line 1137 skipping to change at line 1185
path += serverPath.midRef(folder->remotePathTrailingSlash().length()); path += serverPath.midRef(folder->remotePathTrailingSlash().length());
if (QFile::exists(path)) { if (QFile::exists(path)) {
re.append(path); re.append(path);
} }
} }
return re; return re;
} }
void FolderMan::removeFolder(Folder *f) void FolderMan::removeFolder(Folder *f)
{ {
if (!f) { if (!OC_ENSURE(f)) {
qCCritical(lcFolderMan) << "Can not remove null folder";
return; return;
} }
qCInfo(lcFolderMan) << "Removing " << f->alias(); qCInfo(lcFolderMan) << "Removing " << f->alias();
const bool currentlyRunning = f->isSyncRunning(); const bool currentlyRunning = f->isSyncRunning();
if (currentlyRunning) { if (currentlyRunning) {
// abort the sync now // abort the sync now
f->slotTerminateSync(); f->slotTerminateSync();
} }
skipping to change at line 1268 skipping to change at line 1315
QNetworkProxy(QNetworkProxy::DefaultProxy)); QNetworkProxy(QNetworkProxy::DefaultProxy));
} }
} }
} }
} }
void FolderMan::setDirtyNetworkLimits() void FolderMan::setDirtyNetworkLimits()
{ {
for (auto *f : qAsConst(_folderMap)) { for (auto *f : qAsConst(_folderMap)) {
// set only in busy folders. Otherwise they read the config anyway. // set only in busy folders. Otherwise they read the config anyway.
if (f && f->isBusy()) { if (f && f->isSyncRunning()) {
f->setDirtyNetworkLimits(); f->setDirtyNetworkLimits();
} }
} }
} }
TrayOverallStatusResult FolderMan::trayOverallStatus(const QList<Folder *> &fold ers) TrayOverallStatusResult FolderMan::trayOverallStatus(const QList<Folder *> &fold ers)
{ {
TrayOverallStatusResult result; TrayOverallStatusResult result;
// if one of them has an error -> show error // if one of them has an error -> show error
skipping to change at line 1496 skipping to change at line 1543
{ {
if (numberOfSyncJournals(path) > 1) { if (numberOfSyncJournals(path) > 1) {
return tr("Multiple accounts are sharing the folder %1.\n" return tr("Multiple accounts are sharing the folder %1.\n"
"This configuration is know to lead to dataloss and is no long er supported.\n" "This configuration is know to lead to dataloss and is no long er supported.\n"
"Please consider removing this folder from the account and add ing it again.") "Please consider removing this folder from the account and add ing it again.")
.arg(path); .arg(path);
} }
return {}; return {};
} }
bool FolderMan::checkVfsAvailability(const QString &path) const bool FolderMan::checkVfsAvailability(const QString &path, Vfs::Mode mode) const
{ {
return unsupportedConfiguration(path) && Vfs::checkAvailability(path); return unsupportedConfiguration(path) && Vfs::checkAvailability(path, mode);
} }
} // namespace OCC } // namespace OCC
 End of changes. 16 change blocks. 
17 lines changed or deleted 70 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)