"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/gui/folder.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.

folder.cpp  (ownCloud-2.9.0.5150.tar.xz):folder.cpp  (ownCloud-2.9.1.5500.tar.xz)
skipping to change at line 50 skipping to change at line 50
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
#include <QSettings> #include <QSettings>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QApplication> #include <QApplication>
static const char versionC[] = "version"; namespace {
/*
* [Accounts]
* 1\Folders\4\version=2
* 1\FoldersWithPlaceholders\3\version=3
*/
auto versionC()
{
return QStringLiteral("version");
}
constexpr int WinVfsSettingsVersion = 4;
constexpr int SettingsVersion = 2;
}
namespace OCC { namespace OCC {
Q_LOGGING_CATEGORY(lcFolder, "gui.folder", QtInfoMsg) Q_LOGGING_CATEGORY(lcFolder, "gui.folder", QtInfoMsg)
Folder::Folder(const FolderDefinition &definition, Folder::Folder(const FolderDefinition &definition,
AccountState *accountState, std::unique_ptr<Vfs> vfs, AccountState *accountState, std::unique_ptr<Vfs> vfs,
QObject *parent) QObject *parent)
: QObject(parent) : QObject(parent)
, _accountState(accountState) , _accountState(accountState)
skipping to change at line 80 skipping to change at line 94
_timeSinceLastSyncDone.start(); _timeSinceLastSyncDone.start();
_timeSinceLastEtagCheckDone.start(); _timeSinceLastEtagCheckDone.start();
SyncResult::Status status = SyncResult::NotYetStarted; SyncResult::Status status = SyncResult::NotYetStarted;
if (definition.paused) { if (definition.paused) {
status = SyncResult::Paused; status = SyncResult::Paused;
} }
_syncResult.setStatus(status); _syncResult.setStatus(status);
// check if the local path exists // check if the local path exists
checkLocalPath(); const auto folderOk = checkLocalPath();
_syncResult.setFolder(_definition.alias); _syncResult.setFolder(_definition.alias);
_engine.reset(new SyncEngine(_accountState->account(), path(), remotePath(), &_journal)); _engine.reset(new SyncEngine(_accountState->account(), path(), remotePath(), &_journal));
// pass the setting if hidden files are to be ignored, will be read in csync _update // pass the setting if hidden files are to be ignored, will be read in csync _update
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles); _engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
ConfigFile::setupDefaultExcludeFilePaths(_engine->excludedFiles()); ConfigFile::setupDefaultExcludeFilePaths(_engine->excludedFiles());
if (!reloadExcludes()) if (!reloadExcludes())
qCWarning(lcFolder, "Could not read system exclude file"); qCWarning(lcFolder, "Could not read system exclude file");
skipping to change at line 144 skipping to change at line 158
SyncEngine::wipeVirtualFiles(path(), _journal, *_vfs); SyncEngine::wipeVirtualFiles(path(), _journal, *_vfs);
// Then switch to winvfs mode // Then switch to winvfs mode
_vfs.reset(winvfs.release()); _vfs.reset(winvfs.release());
_definition.virtualFilesMode = Vfs::WindowsCfApi; _definition.virtualFilesMode = Vfs::WindowsCfApi;
} }
} }
saveToSettings(); saveToSettings();
} }
// Initialize the vfs plugin if (folderOk) {
startVfs(); // Initialize the vfs plugin
startVfs();
}
} }
Folder::~Folder() Folder::~Folder()
{ {
// If wipeForRemoval() was called the vfs has already shut down. // If wipeForRemoval() was called the vfs has already shut down.
if (_vfs) if (_vfs)
_vfs->stop(); _vfs->stop();
// Reset then engine first as it will abort and try to access members of the Folder // Reset then engine first as it will abort and try to access members of the Folder
_engine.reset(); _engine.reset();
} }
void Folder::checkLocalPath() bool Folder::checkLocalPath()
{ {
#ifdef Q_OS_WIN
Utility::NtfsPermissionLookupRAII ntfs_perm;
#endif
const QFileInfo fi(_definition.localPath); const QFileInfo fi(_definition.localPath);
_canonicalLocalPath = fi.canonicalFilePath(); _canonicalLocalPath = fi.canonicalFilePath();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// Workaround QTBUG-55896 (Should be fixed in Qt 5.8) // Workaround QTBUG-55896 (Should be fixed in Qt 5.8)
_canonicalLocalPath = _canonicalLocalPath.normalized(QString::NormalizationF orm_C); _canonicalLocalPath = _canonicalLocalPath.normalized(QString::NormalizationF orm_C);
#endif #endif
if (_canonicalLocalPath.isEmpty()) { if (_canonicalLocalPath.isEmpty()) {
qCWarning(lcFolder) << "Broken symlink:" << _definition.localPath; qCWarning(lcFolder) << "Broken symlink:" << _definition.localPath;
_canonicalLocalPath = _definition.localPath; _canonicalLocalPath = _definition.localPath;
} else if (!_canonicalLocalPath.endsWith('/')) { } else if (!_canonicalLocalPath.endsWith('/')) {
_canonicalLocalPath.append('/'); _canonicalLocalPath.append('/');
} }
if (fi.isDir() && fi.isReadable()) { if (fi.isDir() && fi.isReadable() && fi.isWritable()) {
qCDebug(lcFolder) << "Checked local path ok"; qCDebug(lcFolder) << "Checked local path ok";
} else { } else {
QString error;
// Check directory again // Check directory again
if (!FileSystem::fileExists(_definition.localPath, fi)) { if (!FileSystem::fileExists(_definition.localPath, fi)) {
_syncResult.appendErrorString(tr("Local folder %1 does not exist."). error = tr("Local folder %1 does not exist.").arg(_definition.localP
arg(_definition.localPath)); ath);
_syncResult.setStatus(SyncResult::SetupError);
} else if (!fi.isDir()) { } else if (!fi.isDir()) {
_syncResult.appendErrorString(tr("%1 should be a folder but is not." error = tr("%1 should be a folder but is not.").arg(_definition.loca
).arg(_definition.localPath)); lPath);
_syncResult.setStatus(SyncResult::SetupError);
} else if (!fi.isReadable()) { } else if (!fi.isReadable()) {
_syncResult.appendErrorString(tr("%1 is not readable.").arg(_definit error = tr("%1 is not readable.").arg(_definition.localPath);
ion.localPath)); } else if (!fi.isWritable()) {
error = tr("%1 is not writable.").arg(_definition.localPath);
}
if (!error.isEmpty()) {
_syncResult.appendErrorString(error);
_syncResult.setStatus(SyncResult::SetupError); _syncResult.setStatus(SyncResult::SetupError);
return false;
} }
} }
return true;
} }
QString Folder::shortGuiRemotePathOrAppName() const QString Folder::shortGuiRemotePathOrAppName() const
{ {
if (remotePath().length() > 0 && remotePath() != QLatin1String("/")) { if (remotePath().length() > 0 && remotePath() != QLatin1String("/")) {
QString a = QFile(remotePath()).fileName(); QString a = QFile(remotePath()).fileName();
if (a.startsWith('/')) { if (a.startsWith('/')) {
a = a.remove(0, 1); a = a.remove(0, 1);
} }
return a; return a;
skipping to change at line 250 skipping to change at line 275
QString Folder::cleanPath() const QString Folder::cleanPath() const
{ {
QString cleanedPath = QDir::cleanPath(_canonicalLocalPath); QString cleanedPath = QDir::cleanPath(_canonicalLocalPath);
if (cleanedPath.length() == 3 && cleanedPath.endsWith(":/")) if (cleanedPath.length() == 3 && cleanedPath.endsWith(":/"))
cleanedPath.remove(2, 1); cleanedPath.remove(2, 1);
return cleanedPath; return cleanedPath;
} }
bool Folder::isBusy() const
{
return isSyncRunning();
}
bool Folder::isSyncRunning() const bool Folder::isSyncRunning() const
{ {
return _engine->isSyncRunning() || _vfs->isHydrating(); return _engine->isSyncRunning() || _vfs->isHydrating();
} }
QString Folder::remotePath() const QString Folder::remotePath() const
{ {
return _definition.targetPath; return _definition.targetPath;
} }
skipping to change at line 285 skipping to change at line 305
return Utility::concatUrlPath(_accountState->account()->davUrl(), remotePath ()); return Utility::concatUrlPath(_accountState->account()->davUrl(), remotePath ());
} }
bool Folder::syncPaused() const bool Folder::syncPaused() const
{ {
return _definition.paused; return _definition.paused;
} }
bool Folder::canSync() const bool Folder::canSync() const
{ {
return !syncPaused() && accountState()->isConnected(); return !syncPaused() && accountState()->isConnected() && isReady();
}
bool Folder::isReady() const
{
return _vfsIsReady;
} }
bool Folder::dueToSync() const bool Folder::dueToSync() const
{ {
// conditions taken from previous folderman implementation // conditions taken from previous folderman implementation
if (isSyncRunning() || etagJob() || isBusy() || !canSync()) { if (isSyncRunning() || etagJob() || !canSync()) {
return false; return false;
} }
ConfigFile cfg; ConfigFile cfg;
// the default poll time of 30 seconds as it had been in the client forever. // the default poll time of 30 seconds as it had been in the client forever.
// Now with https://github.com/owncloud/client/pull/8777 also the server cap abilities are considered. // Now with https://github.com/owncloud/client/pull/8777 also the server cap abilities are considered.
const auto pta = accountState()->account()->capabilities().remotePollInterva l(); const auto pta = accountState()->account()->capabilities().remotePollInterva l();
const auto polltime = cfg.remotePollInterval(pta); const auto polltime = cfg.remotePollInterval(pta);
const auto timeSinceLastSync = std::chrono::milliseconds(_timeSinceLastEtagC heckDone.elapsed()); const auto timeSinceLastSync = std::chrono::milliseconds(_timeSinceLastEtagC heckDone.elapsed());
skipping to change at line 496 skipping to change at line 521
ocApp()->gui()->slotShowOptionalTrayMessage(tr("Sync Activity"), tex t); ocApp()->gui()->slotShowOptionalTrayMessage(tr("Sync Activity"), tex t);
} }
} }
} }
void Folder::startVfs() void Folder::startVfs()
{ {
OC_ENFORCE(_vfs); OC_ENFORCE(_vfs);
OC_ENFORCE(_vfs->mode() == _definition.virtualFilesMode); OC_ENFORCE(_vfs->mode() == _definition.virtualFilesMode);
const auto result = Vfs::checkAvailability(path(), _vfs->mode());
if (!result) {
_syncResult.appendErrorString(result.error());
_syncResult.setStatus(SyncResult::SetupError);
return;
}
VfsSetupParams vfsParams; VfsSetupParams vfsParams;
vfsParams.filesystemPath = path(); vfsParams.filesystemPath = path();
vfsParams.remotePath = remotePathTrailingSlash(); vfsParams.remotePath = remotePathTrailingSlash();
vfsParams.account = _accountState->account(); vfsParams.account = _accountState->account();
vfsParams.journal = &_journal; vfsParams.journal = &_journal;
vfsParams.providerName = Theme::instance()->appNameGUI(); vfsParams.providerDisplayName = Theme::instance()->appNameGUI();
vfsParams.providerName = Theme::instance()->appName();
vfsParams.providerVersion = Theme::instance()->version(); vfsParams.providerVersion = Theme::instance()->version();
vfsParams.multipleAccountsRegistered = AccountManager::instance()->accounts( ).size() > 1; vfsParams.multipleAccountsRegistered = AccountManager::instance()->accounts( ).size() > 1;
connect(_vfs.data(), &Vfs::beginHydrating, this, &Folder::slotHydrationStart s); connect(_vfs.data(), &Vfs::beginHydrating, this, &Folder::slotHydrationStart s);
connect(_vfs.data(), &Vfs::doneHydrating, this, &Folder::slotHydrationDone); connect(_vfs.data(), &Vfs::doneHydrating, this, &Folder::slotHydrationDone);
connect(&_engine->syncFileStatusTracker(), &SyncFileStatusTracker::fileStatu sChanged, connect(&_engine->syncFileStatusTracker(), &SyncFileStatusTracker::fileStatu sChanged,
_vfs.data(), &Vfs::fileStatusChanged); _vfs.data(), &Vfs::fileStatusChanged);
_vfs->start(vfsParams); connect(_vfs.data(), &Vfs::started, this, [this] {
// Immediately mark the sqlite temporaries as excluded. They get recreat
ed
// on db-open and need to get marked again every time.
QString stateDbFile = _journal.databaseFilePath();
_journal.open();
_vfs->fileStatusChanged(stateDbFile + QStringLiteral("-wal"), SyncFileSt
atus::StatusExcluded);
_vfs->fileStatusChanged(stateDbFile + QStringLiteral("-shm"), SyncFileSt
atus::StatusExcluded);
_vfsIsReady = true;
});
connect(_vfs.data(), &Vfs::error, this, [this](const QString &error) {
_syncResult.appendErrorString(error);
_syncResult.setStatus(SyncResult::SetupError);
_vfsIsReady = false;
});
// Immediately mark the sqlite temporaries as excluded. They get recreated _vfs->start(vfsParams);
// on db-open and need to get marked again every time.
QString stateDbFile = _journal.databaseFilePath();
_journal.open();
_vfs->fileStatusChanged(stateDbFile + "-wal", SyncFileStatus::StatusExcluded
);
_vfs->fileStatusChanged(stateDbFile + "-shm", SyncFileStatus::StatusExcluded
);
} }
int Folder::slotDiscardDownloadProgress() int Folder::slotDiscardDownloadProgress()
{ {
// Delete from journal and from filesystem. // Delete from journal and from filesystem.
QDir folderpath(_definition.localPath); QDir folderpath(_definition.localPath);
QSet<QString> keep_nothing; QSet<QString> keep_nothing;
const QVector<SyncJournalDb::DownloadInfo> deleted_infos = const QVector<SyncJournalDb::DownloadInfo> deleted_infos =
_journal.getAndDeleteStaleDownloadInfos(keep_nothing); _journal.getAndDeleteStaleDownloadInfos(keep_nothing);
for (const auto &deleted_info : deleted_infos) { for (const auto &deleted_info : deleted_infos) {
skipping to change at line 765 skipping to change at line 806
if (_engine->isSyncRunning()) { if (_engine->isSyncRunning()) {
_engine->abort(); _engine->abort();
setSyncState(SyncResult::SyncAbortRequested); setSyncState(SyncResult::SyncAbortRequested);
} }
} }
void Folder::wipeForRemoval() void Folder::wipeForRemoval()
{ {
// prevent interaction with the db etc
_vfsIsReady = false;
// stop reacting to changes
// especially the upcoming deletion of the db
_folderWatcher.reset();
// Delete files that have been partially downloaded. // Delete files that have been partially downloaded.
slotDiscardDownloadProgress(); slotDiscardDownloadProgress();
// Unregister the socket API so it does not keep the .sync_journal file open // Unregister the socket API so it does not keep the .sync_journal file open
FolderMan::instance()->socketApi()->slotUnregisterPath(alias()); FolderMan::instance()->socketApi()->slotUnregisterPath(alias());
_journal.close(); // close the sync journal _journal.close(); // close the sync journal
// Remove db and temporaries // Remove db and temporaries
QString stateDbFile = _engine->journal()->databaseFilePath(); const QString stateDbFile = _engine->journal()->databaseFilePath();
QFile file(stateDbFile); QFile file(stateDbFile);
if (file.exists()) { if (file.exists()) {
if (!file.remove()) { if (!file.remove()) {
qCWarning(lcFolder) << "Failed to remove existing csync StateDB " << stateDbFile; qCCritical(lcFolder) << "Failed to remove existing csync StateDB " < < stateDbFile;
} else { } else {
qCInfo(lcFolder) << "wipe: Removed csync StateDB " << stateDbFile; qCInfo(lcFolder) << "wipe: Removed csync StateDB " << stateDbFile;
} }
} else { } else {
qCWarning(lcFolder) << "statedb is empty, can not remove."; qCWarning(lcFolder) << "statedb is empty, can not remove.";
} }
// Also remove other db related files // Also remove other db related files
QFile::remove(stateDbFile + ".ctmp"); QFile::remove(stateDbFile + ".ctmp");
QFile::remove(stateDbFile + "-shm"); QFile::remove(stateDbFile + "-shm");
skipping to change at line 802 skipping to change at line 850
_vfs->stop(); _vfs->stop();
_vfs->unregisterFolder(); _vfs->unregisterFolder();
_vfs.reset(nullptr); // warning: folder now in an invalid state _vfs.reset(nullptr); // warning: folder now in an invalid state
} }
bool Folder::reloadExcludes() bool Folder::reloadExcludes()
{ {
return _engine->excludedFiles().reloadExcludeFiles(); return _engine->excludedFiles().reloadExcludeFiles();
} }
void Folder::startSync(const QStringList &pathList) void Folder::startSync()
{ {
Q_UNUSED(pathList) Q_ASSERT(isReady());
Q_ASSERT(_folderWatcher);
if (isBusy()) { if (!OC_ENSURE(!isSyncRunning())) {
qCCritical(lcFolder) << "ERROR csync is still running and new sync reque sted."; qCCritical(lcFolder) << "ERROR csync is still running and new sync reque sted.";
return; return;
} }
_timeSinceLastSyncStart.start(); _timeSinceLastSyncStart.start();
_syncResult.setStatus(SyncResult::SyncPrepare); _syncResult.setStatus(SyncResult::SyncPrepare);
emit syncStateChange(); emit syncStateChange();
qCInfo(lcFolder) << "*** Start syncing " << remoteUrl().toString() << "clien t version" qCInfo(lcFolder) << "*** Start syncing " << remoteUrl().toString() << "clien t version"
<< Theme::instance()->aboutVersions(Theme::VersionFormat::O neLiner); << Theme::instance()->aboutVersions(Theme::VersionFormat::O neLiner);
skipping to change at line 1188 skipping to change at line 1237
} }
} }
void Folder::setSaveBackwardsCompatible(bool save) void Folder::setSaveBackwardsCompatible(bool save)
{ {
_saveBackwardsCompatible = save; _saveBackwardsCompatible = save;
} }
void Folder::registerFolderWatcher() void Folder::registerFolderWatcher()
{ {
if (_folderWatcher) if (!isReady()) {
return; return;
if (!QDir(path()).exists()) }
if (_folderWatcher)
return; return;
_folderWatcher.reset(new FolderWatcher(this)); _folderWatcher.reset(new FolderWatcher(this));
connect(_folderWatcher.data(), &FolderWatcher::pathChanged, connect(_folderWatcher.data(), &FolderWatcher::pathChanged,
this, [this](const QString &path) { slotWatchedPathChanged(path, Folder: :ChangeReason::Other); }); this, [this](const QString &path) { slotWatchedPathChanged(path, Folder: :ChangeReason::Other); });
connect(_folderWatcher.data(), &FolderWatcher::lostChanges, connect(_folderWatcher.data(), &FolderWatcher::lostChanges,
this, &Folder::slotNextSyncFullLocalDiscovery); this, &Folder::slotNextSyncFullLocalDiscovery);
connect(_folderWatcher.data(), &FolderWatcher::becameUnreliable, connect(_folderWatcher.data(), &FolderWatcher::becameUnreliable,
this, &Folder::slotWatcherUnreliable); this, &Folder::slotWatcherUnreliable);
_folderWatcher->init(path()); _folderWatcher->init(path());
skipping to change at line 1260 skipping to change at line 1310
{ {
settings.setValue(QLatin1String("localPath"), folder.localPath); settings.setValue(QLatin1String("localPath"), folder.localPath);
settings.setValue(QLatin1String("journalPath"), folder.journalPath); settings.setValue(QLatin1String("journalPath"), folder.journalPath);
settings.setValue(QLatin1String("targetPath"), folder.targetPath); settings.setValue(QLatin1String("targetPath"), folder.targetPath);
settings.setValue(QLatin1String("paused"), folder.paused); settings.setValue(QLatin1String("paused"), folder.paused);
settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFil es); settings.setValue(QLatin1String("ignoreHiddenFiles"), folder.ignoreHiddenFil es);
settings.setValue(QStringLiteral("virtualFilesMode"), Vfs::modeToString(fold er.virtualFilesMode)); settings.setValue(QStringLiteral("virtualFilesMode"), Vfs::modeToString(fold er.virtualFilesMode));
// Ensure new vfs modes won't be attempted by older clients // Ensure new vfs modes won't be attempted by older clients
if (folder.virtualFilesMode == Vfs::WindowsCfApi) { const int version = folder.virtualFilesMode == Vfs::WindowsCfApi ? WinVfsSet
settings.setValue(QLatin1String(versionC), 3); tingsVersion : SettingsVersion;
} else { Q_ASSERT(version <= maxSettingsVersion());
settings.setValue(QLatin1String(versionC), 2); settings.setValue(versionC(), version);
}
// Happens only on Windows when the explorer integration is enabled. // Happens only on Windows when the explorer integration is enabled.
if (!folder.navigationPaneClsid.isNull()) if (!folder.navigationPaneClsid.isNull())
settings.setValue(QLatin1String("navigationPaneClsid"), folder.navigatio nPaneClsid); settings.setValue(QLatin1String("navigationPaneClsid"), folder.navigatio nPaneClsid);
else else
settings.remove(QLatin1String("navigationPaneClsid")); settings.remove(QLatin1String("navigationPaneClsid"));
} }
bool FolderDefinition::load(QSettings &settings, const QString &alias, bool FolderDefinition::load(QSettings &settings, const QString &alias,
FolderDefinition *folder) FolderDefinition *folder)
skipping to change at line 1337 skipping to change at line 1385
p.prepend(QLatin1Char('/')); p.prepend(QLatin1Char('/'));
} }
return p; return p;
} }
QString FolderDefinition::absoluteJournalPath() const QString FolderDefinition::absoluteJournalPath() const
{ {
return QDir(localPath).filePath(journalPath); return QDir(localPath).filePath(journalPath);
} }
QString FolderDefinition::defaultJournalPath(AccountPtr account)
{
return SyncJournalDb::makeDbName(localPath, QStringLiteral("journal"));
}
} // namespace OCC } // namespace OCC
 End of changes. 29 change blocks. 
48 lines changed or deleted 92 lines changed or added

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