From 82c7aeec15719466e0cd4b65ce2189af5989d027 Mon Sep 17 00:00:00 2001 From: alex-z Date: Mon, 5 Dec 2022 19:15:44 +0100 Subject: [PATCH] Fix review comments. Signed-off-by: alex-z --- src/gui/editlocallyjob.cpp | 65 +++++++++++++++++++----------------- src/gui/editlocallyjob.h | 21 ++++++------ src/libsync/syncfileitem.cpp | 2 +- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 699c3db768332..93ca4762800b8 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -29,12 +29,12 @@ namespace OCC { Q_LOGGING_CATEGORY(lcEditLocallyJob, "nextcloud.gui.editlocallyjob", QtInfoMsg) EditLocallyJob::EditLocallyJob(const QString &userId, - const QString &fullRelPath, + const QString &relPath, const QString &token, QObject *parent) : QObject{parent} , _userId(userId) - , _relPath(fullRelPath) + , _relPath(relPath) , _token(token) { } @@ -118,34 +118,7 @@ void EditLocallyJob::remoteTokenCheckResultReceived(const int statusCode) return; } - _folderForFile = findFolderForFile(_relPath, _userId); - - if (!_folderForFile) { - showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); - return; - } - - _relativePathToRemoteRoot = getRelativePathToRemoteRootForFile(); - - if (_relativePathToRemoteRoot.isEmpty()) { - qCWarning(lcEditLocallyJob) << "_relativePathToRemoteRoot is empty for" << _relPath; - showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); - return; - } - - _relPathParent = getRelativePathParent(); - - if (_relPathParent.isEmpty()) { - showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); - return; - } - - if (_relPathParent == QStringLiteral("/")) { - proceedWithSetup(); - return; - } - - fetchRemoteFileParentInfo(); + findAfolderAndConstructPaths(); } void EditLocallyJob::proceedWithSetup() @@ -182,6 +155,38 @@ void EditLocallyJob::proceedWithSetup() Q_EMIT setupFinished(); } +void EditLocallyJob::findAfolderAndConstructPaths() +{ + _folderForFile = findFolderForFile(_relPath, _userId); + + if (!_folderForFile) { + showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); + return; + } + + _relativePathToRemoteRoot = getRelativePathToRemoteRootForFile(); + + if (_relativePathToRemoteRoot.isEmpty()) { + qCWarning(lcEditLocallyJob) << "_relativePathToRemoteRoot is empty for" << _relPath; + showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); + return; + } + + _relPathParent = getRelativePathParent(); + + if (_relPathParent.isEmpty()) { + showError(tr("Could not find a file for local editing. Make sure it is not excluded via selective sync."), _relPath); + return; + } + + if (_relPathParent == QStringLiteral("/")) { + proceedWithSetup(); + return; + } + + fetchRemoteFileParentInfo(); +} + QString EditLocallyJob::prefixSlashToPath(const QString &path) { return path.startsWith('/') ? path : QChar::fromLatin1('/') + path; diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index bdcdf7efb83fd..a2293bffcd7b3 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -17,7 +17,7 @@ #include #include "accountstate.h" -#include +#include "syncfileitem.h" namespace OCC { @@ -33,7 +33,7 @@ class EditLocallyJob : public QObject public: explicit EditLocallyJob(const QString &userId, - const QString &fullRelPath, + const QString &relPath, const QString &token, QObject *parent = nullptr); @@ -51,17 +51,14 @@ public slots: void startSetup(); void startEditLocally(); -private: +private slots: void fetchRemoteFileParentInfo(); - bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise void startSyncBeforeOpening(); void eraseBlacklistRecordForItem(); - [[nodiscard]] const QString getRelativePathToRemoteRootForFile() const; - [[nodiscard]] const QString getRelativePathParent() const; -private slots: void startTokenRemoteCheck(); void proceedWithSetup(); + void findAfolderAndConstructPaths(); void showError(const QString &message, const QString &informativeText); void showErrorNotification(const QString &message, const QString &informativeText) const; @@ -77,13 +74,17 @@ private slots: void openFile(); private: + [[nodiscard]] bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise + [[nodiscard]] const QString getRelativePathToRemoteRootForFile() const; // returns either '/' or a (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/' + [[nodiscard]] const QString getRelativePathParent() const; + bool _tokenVerified = false; AccountStatePtr _accountState; QString _userId; - QString _relPath; - QString _relativePathToRemoteRoot; - QString _relPathParent; + QString _relPath; // full remote path for a file (as on the server) + QString _relativePathToRemoteRoot; // (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/' + QString _relPathParent; // a folder where the file resides ('/' if it is in the first level of a remote root, or e.g. a '/subfolder/a/b/c if it resides in a nested folder) QString _token; SyncFileItemPtr _fileParentItem; diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index d22bda6415138..1727a89389081 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -13,7 +13,7 @@ */ #include "syncfileitem.h" -#include +#include "common/checksums.h" #include "common/syncjournalfilerecord.h" #include "common/utility.h" #include "helpers.h"