Skip to content

Commit 9b7da91

Browse files
committedAug 31, 2018
Private links: improve legacy fileid derivation #6745
1 parent a31eadc commit 9b7da91

6 files changed

+31
-11
lines changed
 

‎src/common/syncjournalfilerecord.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@ SyncJournalFileRecord::SyncJournalFileRecord()
2929
{
3030
}
3131

32-
QByteArray SyncJournalFileRecord::numericFileId() const
32+
QByteArray SyncJournalFileRecord::legacyDeriveNumericFileId() const
3333
{
34-
// Use the id up until the first non-numeric character
34+
// The id property which is stored in _fileId is
35+
// leftpad_with_zero(fileid, 8) + instanceid
36+
// so if it starts with a 0 we know the first 8 bytes
37+
// can be taken.
38+
if (_fileId.startsWith('0')) {
39+
return _fileId.left(8);
40+
}
41+
42+
// Otherwise we don't know exactly how long it is,
43+
// use every digit until the first letter. The instanceid of
44+
// oc >= 6 starts with "oc". This will break for older instances
45+
// that have a digit as the first character of the instance id.
3546
for (int i = 0; i < _fileId.size(); ++i) {
3647
if (_fileId[i] < '0' || _fileId[i] > '9') {
3748
return _fileId.left(i);

‎src/common/syncjournalfilerecord.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ class OCSYNC_EXPORT SyncJournalFileRecord
4545
return !_path.isEmpty();
4646
}
4747

48-
/** Returns the numeric part of the full id in _fileId.
48+
/** Returns a guess for the numeric part of the full id in _fileId.
4949
*
50-
* On the server this is sometimes known as the internal file id.
50+
* On the server this is sometimes known as the internal file id, the "fileid" DAV property.
5151
*
52-
* It is used in the construction of private links.
52+
* It is used in the fallback construction of private links.
53+
*
54+
* New code should not use this function: Request the fileid property from the server.
55+
* In the future we might store the fileid instead of the id, but the migration is complex
56+
* if we don't want to store both.
5357
*/
54-
QByteArray numericFileId() const;
58+
QByteArray legacyDeriveNumericFileId() const;
59+
5560
QDateTime modDateTime() const { return Utility::qDateTimeFromTime_t(_modtime); }
5661

5762
QByteArray _path;

‎src/gui/owncloudgui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
11251125
w = _shareDialogs[localPath];
11261126
} else {
11271127
qCInfo(lcApplication) << "Opening share dialog" << sharePath << localPath << maxSharingPermissions;
1128-
w = new ShareDialog(accountState, sharePath, localPath, maxSharingPermissions, fileRecord.numericFileId(), startPage);
1128+
w = new ShareDialog(accountState, sharePath, localPath, maxSharingPermissions, fileRecord.legacyDeriveNumericFileId(), startPage);
11291129
w->setAttribute(Qt::WA_DeleteOnClose, true);
11301130

11311131
_shareDialogs[localPath] = w;

‎src/gui/protocolwidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void ProtocolItem::openContextMenu(QPoint globalPos, QTreeWidgetItem *item, QWid
141141
// "Open in Browser" action
142142
auto openInBrowser = menu->addAction(ProtocolWidget::tr("Open in browser"));
143143
QObject::connect(openInBrowser, &QAction::triggered, parent, [parent, account, rec]() {
144-
fetchPrivateLinkUrl(account, rec._path, rec.numericFileId(), parent,
144+
fetchPrivateLinkUrl(account, rec._path, rec.legacyDeriveNumericFileId(), parent,
145145
[parent](const QString &url) {
146146
Utility::openBrowser(url, parent);
147147
});

‎src/gui/socketapi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void SocketApi::fetchPrivateLinkUrlHelper(const QString &localFile, const std::f
580580
fetchPrivateLinkUrl(
581581
fileData.folder->accountState()->account(),
582582
fileData.serverRelativePath,
583-
record.numericFileId(),
583+
record.legacyDeriveNumericFileId(),
584584
this,
585585
targetFun);
586586
}

‎test/testsyncjournaldb.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ private slots:
176176

177177
// Typical 8-digit padded id
178178
record._fileId = "00000001abcd";
179-
QCOMPARE(record.numericFileId(), QByteArray("00000001"));
179+
QCOMPARE(record.legacyDeriveNumericFileId(), QByteArray("00000001"));
180+
181+
// Typical 8-digit padded id with instanceid that starts with a digit
182+
record._fileId = "00000001999";
183+
QCOMPARE(record.legacyDeriveNumericFileId(), QByteArray("00000001"));
180184

181185
// When the numeric id overflows the 8-digit boundary
182186
record._fileId = "123456789ocidblaabcd";
183-
QCOMPARE(record.numericFileId(), QByteArray("123456789"));
187+
QCOMPARE(record.legacyDeriveNumericFileId(), QByteArray("123456789"));
184188
}
185189

186190
void testConflictRecord()

0 commit comments

Comments
 (0)
Please sign in to comment.