Skip to content

Commit

Permalink
receive and decode tokens for locks
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Sep 25, 2024
1 parent 5902ff5 commit bc16063
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
item->_lockEditorApp = serverEntry.lockEditorApp;
item->_lockTime = serverEntry.lockTime;
item->_lockTimeout = serverEntry.lockTimeout;
item->_lockToken = serverEntry.lockToken;

qCDebug(lcDisco()) << "item lock for:" << item->_file
<< item->_locked
Expand All @@ -676,7 +677,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
<< item->_lockOwnerType
<< item->_lockEditorApp
<< item->_lockTime
<< item->_lockTimeout;
<< item->_lockTimeout
<< item->_lockToken;

// Check for missing server data
{
Expand Down
7 changes: 5 additions & 2 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ void DiscoverySingleDirectoryJob::start()
<< "http://nextcloud.org/ns:lock-owner-type"
<< "http://nextcloud.org/ns:lock-owner-editor"
<< "http://nextcloud.org/ns:lock-time"
<< "http://nextcloud.org/ns:lock-timeout";
<< "http://nextcloud.org/ns:lock-timeout"
<< "http://nextcloud.org/ns:lock-token";
}
props << "http://nextcloud.org/ns:is-mount-root";

Expand Down Expand Up @@ -545,7 +546,9 @@ static void propertyMapToRemoteInfo(const QMap<QString, QString> &map, RemotePer
result.lockTimeout = 0;
}
}

if (property == "lock-token") {
result.lockToken = value;
}
}

if (result.isDirectory && map.contains("size")) {
Expand Down
1 change: 1 addition & 0 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct RemoteInfo
QString lockEditorApp;
qint64 lockTime = 0;
qint64 lockTimeout = 0;
QString lockToken;
};

struct LocalInfo
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/lockfilejobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void LockFileJob::setFileRecordLocked(SyncJournalFileRecord &record) const
record._lockstate._lockEditorApp = _editorName;
record._lockstate._lockTime = _lockTime;
record._lockstate._lockTimeout = _lockTimeout;
record._lockstate._lockToken = _lockToken;
if (!_etag.isEmpty()) {
record._etag = _etag;
}
Expand All @@ -129,6 +130,7 @@ void LockFileJob::resetState()
_userId.clear();
_lockTime = 0;
_lockTimeout = 0;
_lockToken.clear();
}

SyncJournalFileRecord LockFileJob::handleReply()
Expand Down Expand Up @@ -241,6 +243,8 @@ void LockFileJob::decodeStartElement(const QString &name,
_editorName = reader.readElementText();
} else if (name == QStringLiteral("getetag")) {
_etag = reader.readElementText().toUtf8();
} else if (name == QStringLiteral("lock-token")) {
_lockToken = reader.readElementText();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libsync/lockfilejobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class OWNCLOUDSYNC_EXPORT LockFileJob : public AbstractNetworkJob
QByteArray _etag;
qint64 _lockTime = 0;
qint64 _lockTimeout = 0;
QString _lockToken;
QString _remoteSyncPathWithTrailingSlash;
QString _localSyncPath;
};
Expand Down
1 change: 1 addition & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ void OCC::SyncEngine::slotItemDiscovered(const OCC::SyncFileItemPtr &item)
lockInfo._lockOwnerType = static_cast<qint64>(item->_lockOwnerType);
lockInfo._lockOwnerDisplayName = item->_lockOwnerDisplayName;
lockInfo._lockEditorApp = item->_lockOwnerDisplayName;
lockInfo._lockToken = item->_lockToken;

if (!_journal->updateLocalMetadata(item->_file, item->_modtime, item->_size, item->_inode, lockInfo)) {
qCWarning(lcEngine) << "Could not update local metadata for file" << item->_file;
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ SyncJournalFileRecord SyncFileItem::toSyncJournalFileRecordWithInode(const QStri
rec._lockstate._lockEditorApp = _lockEditorApp;
rec._lockstate._lockTime = _lockTime;
rec._lockstate._lockTimeout = _lockTimeout;
rec._lockstate._lockToken = _lockToken;

// Update the inode if possible
rec._inode = _inode;
Expand Down Expand Up @@ -163,6 +164,7 @@ SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRec
item->_lockEditorApp = rec._lockstate._lockEditorApp;
item->_lockTime = rec._lockstate._lockTime;
item->_lockTimeout = rec._lockstate._lockTimeout;
item->_lockToken = rec._lockstate._lockToken;
item->_sharedByMe = rec._sharedByMe;
item->_isShared = rec._isShared;
item->_lastShareStateFetchedTimestamp = rec._lastShareStateFetchedTimestamp;
Expand Down Expand Up @@ -251,6 +253,7 @@ void SyncFileItem::updateLockStateFromDbRecord(const SyncJournalFileRecord &dbRe
_lockEditorApp = dbRecord._lockstate._lockEditorApp;
_lockTime = dbRecord._lockstate._lockTime;
_lockTimeout = dbRecord._lockstate._lockTimeout;
_lockToken = dbRecord._lockstate._lockToken;
}

}
1 change: 1 addition & 0 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
QString _lockEditorApp;
qint64 _lockTime = 0;
qint64 _lockTimeout = 0;
QString _lockToken;

bool _isShared = false;
time_t _lastShareStateFetchedTimestamp = 0;
Expand Down

0 comments on commit bc16063

Please sign in to comment.