Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable9.1] Prefilter inaccessible shares in DefaultShareProvider::getSharedWith() #26050

Merged
merged 1 commit into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,25 @@ public function getSharesByPath(Node $path) {
return $shares;
}

/**
* Returns whether the given database result can be interpreted as
* a share with accessible file (not trashed, not deleted)
*/
private function isAccessibleResult($data) {
// exclude shares leading to deleted file entries
if ($data['fileid'] === null) {
return false;
}

// exclude shares leading to trashbin on home storages
$pathSections = explode('/', $data['path'], 2);
// FIXME: would not detect rare md5'd home storage case properly
if ($pathSections[0] !== 'files' && explode(':', $data['storage_string_id'], 2)[0] === 'home') {
return false;
}
return true;
}

/**
* @inheritdoc
*/
Expand All @@ -591,11 +610,14 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
//Get shares directly with this user
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share');
$qb->select('s.*', 'f.fileid', 'f.path')
->selectAlias('st.id', 'storage_string_id')
->from('share', 's')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));

// Order by id
$qb->orderBy('id');
$qb->orderBy('s.id');

// Set limit and offset
if ($limit !== -1) {
Expand All @@ -618,7 +640,9 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$cursor = $qb->execute();

while($data = $cursor->fetch()) {
$shares[] = $this->createShare($data);
if ($this->isAccessibleResult($data)) {
$shares[] = $this->createShare($data);
}
}
$cursor->closeCursor();

Expand All @@ -639,9 +663,12 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
}

$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
->orderBy('id')
$qb->select('s.*', 'f.fileid', 'f.path')
->selectAlias('st.id', 'storage_string_id')
->from('share', 's')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
->orderBy('s.id')
->setFirstResult(0);

if ($limit !== -1) {
Expand Down Expand Up @@ -671,7 +698,10 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$offset--;
continue;
}
$shares2[] = $this->createShare($data);

if ($this->isAccessibleResult($data)) {
$shares2[] = $this->createShare($data);
}
}
$cursor->closeCursor();
}
Expand Down
Loading