Skip to content

Commit

Permalink
improve query to detect shared mountpoint in folder
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Apr 20, 2022
1 parent caebdc2 commit 83417a6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,28 +670,34 @@ public function getSharesInFolder($userId, Folder $node, $reshares) {
);
}

// todo? maybe get these from the oc_mounts table
$childMountNodes = array_filter($node->getDirectoryListing(), function (Node $node) {
return $node->getInternalPath() === '';
});
$childMountRootIds = array_map(function (Node $node) {
return $node->getId();
}, $childMountNodes);

$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
$qb->leftJoin('s', 'mounts', 'm', $qb->expr()->eq('s.file_source', 'm.root_id'));
$absolutePath = $node->getMountPoint()->getMountPoint() . $node->getInternalPath();

$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
$qb->expr()->in('f.fileid', $qb->createNamedParameter($childMountRootIds, IQueryBuilder::PARAM_INT_ARRAY))
$qb->expr()->like('m.mount_point', $qb->createNamedParameter(
// note that this will select to many items, (inside sub folders) these are filtered out later
$qb->getConnection()->escapeLikeParameter($absolutePath) . '/%'
))
)
);

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

$cursor = $qb->execute();
$shares = [];
while ($data = $cursor->fetch()) {
$shares[$data['fileid']][] = $this->createShare($data);
if ($data['mount_point'] === null) {
$shares[$data['fileid']][] = $this->createShare($data);
} else {
// check if the shared mountpoint is a direct child
$relativePath = trim(substr($data['mount_point'], strlen($absolutePath)), '/');
if (strpos($relativePath, '/') === false) {
$shares[$data['fileid']][] = $this->createShare($data);
}
}
}
$cursor->closeCursor();

Expand Down

0 comments on commit 83417a6

Please sign in to comment.