Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: remove non-shallow getSharesInFolder
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 25, 2024
commit 2ce83d855c7c299ce89489efa17a836c84bee81d
7 changes: 1 addition & 6 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,7 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t

$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));

$qb->andWhere($qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT)));
if ($shallow) {
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId(), IQueryBuilder::PARAM_INT)));
} else {
$qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
}
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change about?


$qb->orderBy('id');

Expand Down
32 changes: 27 additions & 5 deletions apps/files_sharing/lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
*/
namespace OCA\Files_Sharing;

use OC\Files\Cache\FileAccess;
use OC\Files\Mount\MountPoint;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Server;
use OCP\Share\IShare;

class Updater {
Expand Down Expand Up @@ -58,20 +60,40 @@ private static function moveShareInOrOutOfShare($path): void {
if ($userFolder === null) {
return;
}
$user = $userFolder->getOwner();
if (!$user) {
throw new \Exception("user folder has no owner");
}

$src = $userFolder->get($path);

$shareManager = \OC::$server->getShareManager();

// FIXME: should CIRCLES be included here ??
$shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1);
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1));
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1));
$shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1);
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1));
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1));

if ($src instanceof Folder) {
$subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false);
$cacheAccess = Server::get(FileAccess::class);

$sourceStorageId = $src->getStorage()->getCache()->getNumericStorageId();
$sourceInternalPath = $src->getInternalPath();
$subShares = array_merge(
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER),
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP),
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM),
Comment on lines +83 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did the $src parameter go?

);
$shareSourceIds = array_map(fn (IShare $share) => $share->getNodeId(), $subShares);
$shareSources = $cacheAccess->getByFileIdsInStorage($shareSourceIds, $sourceStorageId);
foreach ($subShares as $subShare) {
$shares = array_merge($shares, array_values($subShare));
$shareCacheEntry = $shareSources[$subShare->getNodeId()] ?? null;
if (
$shareCacheEntry &&
str_starts_with($shareCacheEntry->getPath(), $sourceInternalPath . '/')
) {
$shares[] = $subShare;
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,12 +1069,7 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t

$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));

$qb->andWhere($qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT)));
if ($shallow) {
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
} else {
$qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
}
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));

$qb->orderBy('id');

Expand Down
28 changes: 6 additions & 22 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,28 +692,12 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t
}, $childMountNodes);

$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
$storageFilter = $qb->expr()->eq('f.storage', $qb->createNamedParameter($node->getMountPoint()->getNumericStorageId(), IQueryBuilder::PARAM_INT));
if ($shallow) {
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->andX(
$storageFilter,
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
),
$qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
)
);
} else {
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->andX(
$storageFilter,
$qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConn->escapeLikeParameter($node->getInternalPath()) . '/%')),
),
$qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
)
);
}
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
$qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
)
);

$qb->orderBy('id');

Expand Down
5 changes: 4 additions & 1 deletion lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,12 @@ public function moveShare(IShare $share, $recipientId) {

public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) {
$providers = $this->factory->getAllProviders();
if (!$shallow) {
throw new \Exception("non-shallow getSharesInFolder is no longer supported");
}

return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares, $shallow) {
$newShares = $provider->getSharesInFolder($userId, $node, $reshares, $shallow);
$newShares = $provider->getSharesInFolder($userId, $node, $reshares);
foreach ($newShares as $fid => $data) {
if (!isset($shares[$fid])) {
$shares[$fid] = [];
Expand Down