Skip to content

Commit

Permalink
Refactor bool flags to enums and remove leftover cpp file.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Aug 23, 2023
1 parent 79d26d3 commit 9f7f96c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 397 deletions.
3 changes: 2 additions & 1 deletion src/libsync/basepropagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void BasePropagateRemoteDeleteEncrypted::fetchMetadataForPath(const QString &pat

void BasePropagateRemoteDeleteEncrypted::uploadMetadata(bool keepLock)
{
_encryptedFolderMetadataHandler->uploadMetadata(keepLock);
_encryptedFolderMetadataHandler->uploadMetadata(keepLock ? EncryptedFolderMetadataHandler::UploadMode::KeepLock
: EncryptedFolderMetadataHandler::UploadMode::DoNotKeepLock);
}

void BasePropagateRemoteDeleteEncrypted::slotFolderUnLockFinished(const QByteArray &folderId, int statusCode)
Expand Down
24 changes: 12 additions & 12 deletions src/libsync/encryptedfoldermetadatahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace OCC {

Q_LOGGING_CATEGORY(lcFetchAndUploadE2eeFolderMetadataJob, "nextcloud.sync.propagator.fetchanduploade2eefoldermetadatajob", QtInfoMsg)
Q_LOGGING_CATEGORY(lcFetchAndUploadE2eeFolderMetadataJob, "nextcloud.sync.propagator.encryptedfoldermetadatahandler", QtInfoMsg)

}

Expand All @@ -45,26 +45,26 @@ EncryptedFolderMetadataHandler::EncryptedFolderMetadataHandler(const AccountPtr
RootEncryptedFolderInfo::createRootPath(folderPath, pathForTopLevelFolder));
}

void EncryptedFolderMetadataHandler::fetchMetadata(bool allowEmptyMetadata)
void EncryptedFolderMetadataHandler::fetchMetadata(const FetchMode fetchMode)
{
_allowEmptyMetadata = allowEmptyMetadata;
_fetchMode = fetchMode;
fetchFolderEncryptedId();
}

void EncryptedFolderMetadataHandler::fetchMetadata(const RootEncryptedFolderInfo &rootEncryptedFolderInfo, bool allowEmptyMetadata)
void EncryptedFolderMetadataHandler::fetchMetadata(const RootEncryptedFolderInfo &rootEncryptedFolderInfo, const FetchMode fetchMode)
{
_rootEncryptedFolderInfo = rootEncryptedFolderInfo;
if (_rootEncryptedFolderInfo.path.isEmpty()) {
qCWarning(lcFetchAndUploadE2eeFolderMetadataJob) << "Error fetching metadata for" << _folderPath << ". Invalid _rootEncryptedFolderInfo!";
emit fetchFinished(-1, tr("Error fetching metadata."));
return;
}
fetchMetadata(allowEmptyMetadata);
fetchMetadata(fetchMode);
}

void EncryptedFolderMetadataHandler::uploadMetadata(bool keepLock)
void EncryptedFolderMetadataHandler::uploadMetadata(const UploadMode uploadMode)
{
_keepLockedAfterUpdate = keepLock;
_uploadMode = uploadMode;
if (!_folderToken.isEmpty()) {
// use existing token
startUploadMetadata();
Expand Down Expand Up @@ -163,7 +163,7 @@ void EncryptedFolderMetadataHandler::slotMetadataReceived(const QJsonDocument &j
return;
}

_allowEmptyMetadata = false;
_fetchMode = FetchMode::NonEmptyMetadata;

if (statusCode != 200 && statusCode != 404) {
// neither successfully fetched, nor a folder without a metadata, fail further logic
Expand All @@ -189,7 +189,7 @@ void EncryptedFolderMetadataHandler::slotMetadataReceived(const QJsonDocument &j
void EncryptedFolderMetadataHandler::slotMetadataReceivedError(const QByteArray &folderId, int httpReturnCode)
{
Q_UNUSED(folderId);
if (_allowEmptyMetadata) {
if (_fetchMode == FetchMode::AllowEmptyMetadata) {
qCDebug(lcFetchAndUploadE2eeFolderMetadataJob) << "Error Getting the encrypted metadata. Pretend we got empty metadata. In case when posting it for the first time.";
_isNewMetadataCreated = true;
slotMetadataReceived({}, httpReturnCode);
Expand Down Expand Up @@ -229,7 +229,7 @@ void EncryptedFolderMetadataHandler::unlockFolder(bool success)
return;
}

if (!_keepLockedAfterUpdate) {
if (_uploadMode == UploadMode::DoNotKeepLock) {
if (success) {
connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadSuccess);
} else {
Expand Down Expand Up @@ -290,7 +290,7 @@ void EncryptedFolderMetadataHandler::slotUploadMetadataSuccess(const QByteArray
{
Q_UNUSED(folderId);
qCDebug(lcFetchAndUploadE2eeFolderMetadataJob) << "Uploading of the metadata success.";
if (_keepLockedAfterUpdate || !_isFolderLocked) {
if (_uploadMode == UploadMode::KeepLock || !_isFolderLocked) {
slotEmitUploadSuccess();
return;
}
Expand All @@ -303,7 +303,7 @@ void EncryptedFolderMetadataHandler::slotUploadMetadataError(const QByteArray &f
qCDebug(lcFetchAndUploadE2eeFolderMetadataJob) << "Update metadata error for folder" << folderId << "with error" << httpReturnCode;
qCDebug(lcFetchAndUploadE2eeFolderMetadataJob) << "Unlocking the folder.";
_uploadErrorCode = httpReturnCode;
if (_isFolderLocked && !_keepLockedAfterUpdate) {
if (_isFolderLocked && _uploadMode == UploadMode::DoNotKeepLock) {
connect(this, &EncryptedFolderMetadataHandler::folderUnlocked, this, &EncryptedFolderMetadataHandler::slotEmitUploadError);
unlockFolder(false);
return;
Expand Down
20 changes: 15 additions & 5 deletions src/libsync/encryptedfoldermetadatahandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class OWNCLOUDSYNC_EXPORT EncryptedFolderMetadataHandler : public QObject
Q_OBJECT

public:
enum class FetchMode {
NonEmptyMetadata = 0,
AllowEmptyMetadata
};

enum class UploadMode {
DoNotKeepLock = 0,
KeepLock
};

explicit EncryptedFolderMetadataHandler(const AccountPtr &account,
const QString &folderPath,
SyncJournalDb *const journalDb,
Expand All @@ -50,9 +60,9 @@ class OWNCLOUDSYNC_EXPORT EncryptedFolderMetadataHandler : public QObject
[[nodiscard]] const bool isUnlockRunning() const;
[[nodiscard]] const bool isFolderLocked() const;

void fetchMetadata(const RootEncryptedFolderInfo &rootEncryptedFolderInfo, bool allowEmptyMetadata = false);
void fetchMetadata(bool allowEmptyMetadata = false);
void uploadMetadata(bool keepLock = false);
void fetchMetadata(const RootEncryptedFolderInfo &rootEncryptedFolderInfo, const FetchMode fetchMode = FetchMode::NonEmptyMetadata);
void fetchMetadata(const FetchMode fetchMode = FetchMode::NonEmptyMetadata);
void uploadMetadata(const UploadMode uploadMode = UploadMode::DoNotKeepLock);
void unlockFolder(bool success = true);

private:
Expand Down Expand Up @@ -96,11 +106,11 @@ public: signals:

int _uploadErrorCode = 200;

bool _allowEmptyMetadata = false;
FetchMode _fetchMode = FetchMode::NonEmptyMetadata;
bool _isFolderLocked = false;
bool _isUnlockRunning = false;
bool _isNewMetadataCreated = false;
bool _keepLockedAfterUpdate = false;
UploadMode _uploadMode = UploadMode::DoNotKeepLock;
};

}
Loading

0 comments on commit 9f7f96c

Please sign in to comment.