Skip to content

Commit

Permalink
Discovery: consider also the "shared by me" as shared
Browse files Browse the repository at this point in the history
The "S" in the permission is only for the "Shared with me" files.
It is only used to show the shared status in the overlay icons.
But we also wish to show the shared status for files that are shared
"by" the users. We can find that out using the 'share-types' webdav
property. If set, then we are sharing the object.
We fake a 'S' in the permission as for our purpose, they mean the same.

Issue #4788
  • Loading branch information
ogoffart committed Nov 15, 2016
1 parent 2723cd2 commit 2d6e473
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QUrl>
#include "account.h"
#include <QFileInfo>
#include <cstring>

namespace OCC {

Expand Down Expand Up @@ -236,7 +237,8 @@ void DiscoverySingleDirectoryJob::start()
QList<QByteArray> props;
props << "resourcetype" << "getlastmodified" << "getcontentlength" << "getetag"
<< "http://owncloud.org/ns:id" << "http://owncloud.org/ns:downloadURL"
<< "http://owncloud.org/ns:dDC" << "http://owncloud.org/ns:permissions";
<< "http://owncloud.org/ns:dDC" << "http://owncloud.org/ns:permissions"
<< "http://owncloud.org/ns:share-types";
if (_isRootPath)
props << "http://owncloud.org/ns:data-fingerprint";

Expand Down Expand Up @@ -308,9 +310,25 @@ static csync_vio_file_stat_t* propertyMapToFileStat(const QMap<QString,QString>
} else {
qWarning() << "permissions too large" << v;
}
} else if (property == "share-types" && !value.isEmpty()) {
// Since QMap is sorted, "share-types" is always "permissions".
if (file_stat->remotePerm[0] == '\0' || !(file_stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_PERM)) {
qWarning() << "Server returned a share type, but no permissions?";
} else {
// S means shared with me.
// But for our purpose, we want to know if the file is shared. It does not matter
// if we are the owner or not.
// Piggy back on the persmission field 'S'
if (!std::strchr(file_stat->remotePerm, 'S')) {
if (std::strlen(file_stat->remotePerm) < sizeof(file_stat->remotePerm)-1) {
std::strcat(file_stat->remotePerm, "S");
} else {
qWarning() << "permissions too large" << file_stat->remotePerm;
}
}
}
}
}

return file_stat;
}

Expand Down
4 changes: 3 additions & 1 deletion test/syncenginetestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class FileInfo : public FileModifier
QDateTime lastModified = QDateTime::currentDateTime().addDays(-7);
QString etag = generateEtag();
QByteArray fileId = generateFileId();
QByteArray extraDavProperties;
qint64 size = 0;
char contentChar = 'W';

Expand Down Expand Up @@ -314,6 +315,7 @@ class FakePropfindReply : public QNetworkReply
xml.writeTextElement(davUri, QStringLiteral("getetag"), fileInfo.etag);
xml.writeTextElement(ocUri, QStringLiteral("permissions"), fileInfo.isShared ? QStringLiteral("SRDNVCKW") : QStringLiteral("RDNVCKW"));
xml.writeTextElement(ocUri, QStringLiteral("id"), fileInfo.fileId);
buffer.write(fileInfo.extraDavProperties);
xml.writeEndElement(); // prop
xml.writeTextElement(davUri, QStringLiteral("status"), "HTTP/1.1 200 OK");
xml.writeEndElement(); // propstat
Expand Down Expand Up @@ -648,7 +650,7 @@ class FakeFolder
OCC::SyncEngine &syncEngine() const { return *_syncEngine; }

FileModifier &localModifier() { return _localModifier; }
FileModifier &remoteModifier() { return _fakeQnam->currentRemoteState(); }
FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); }
FileInfo currentLocalState() {
QDir rootDir{_tempDir.path()};
FileInfo rootTemplate;
Expand Down
6 changes: 6 additions & 0 deletions test/testsyncfilestatustracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ private slots:
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
fakeFolder.remoteModifier().insert("S/s0");
fakeFolder.remoteModifier().appendByte("S/s1");
fakeFolder.remoteModifier().insert("B/b3");
fakeFolder.remoteModifier().find("B/b3")->extraDavProperties
= "<oc:share-types><oc:share-type>0</oc:share-type></oc:share-types>";

StatusPushSpy statusSpy(fakeFolder.syncEngine());

fakeFolder.scheduleSync();
Expand All @@ -395,6 +399,8 @@ private slots:
QEXPECT_FAIL("", "We currently only know if a new file is shared on the second sync, after a PROPFIND.", Continue);
QCOMPARE(statusSpy.statusOf("S/s0"), sharedUpToDateStatus);
QCOMPARE(statusSpy.statusOf("S/s1"), sharedUpToDateStatus);
QCOMPARE(statusSpy.statusOf("B/b1").sharedWithMe(), false);
QCOMPARE(statusSpy.statusOf("B/b3"), sharedUpToDateStatus);

QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
Expand Down

0 comments on commit 2d6e473

Please sign in to comment.