Skip to content

Commit e3658ef

Browse files
authored
Merge pull request #2338 from nextcloud/fix/share_path_matching
fix: do not ignore shares if child share is missing
2 parents e15cbff + b0f2b18 commit e3658ef

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/Db/CoreQueryBuilder.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,27 @@ public function limitToFileSource(int $nodeId): void {
346346
}
347347

348348
public function limitToFileTarget(string $target, string $alias): void {
349-
$this->exprLimit('file_target', $target, $alias);
349+
$this->andWhere(
350+
$this->expr()->orX(
351+
$this->exprLimit('file_target', $target, $alias),
352+
$this->expr()->andX(
353+
$this->exprLimitNull('file_target', false, $alias),
354+
$this->exprLimit('file_target', $target),
355+
),
356+
),
357+
);
350358
}
351359

352360
public function limitToFileTargetLike(string $target, string $alias): void {
353-
$this->exprLike('file_target', $target, $alias);
361+
$this->andWhere(
362+
$this->expr()->orX(
363+
$this->exprLike('file_target', $target, $alias),
364+
$this->expr()->andX(
365+
$this->exprLimitNull('file_target', false, $alias),
366+
$this->exprLike('file_target', $target),
367+
),
368+
),
369+
);
354370
}
355371

356372
/**

lib/Db/ShareWrapperRequest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,15 @@ public function getSharedWithByPath(
384384
$childAlias = $qb->leftJoinShareChild(CoreQueryBuilder::SHARE);
385385

386386
if ($forChildren) {
387-
$qb->limitToFileTargetLike($path . '_%', $childAlias);
387+
$userId = $federatedUser->getUserId();
388+
$path = str_replace('/' . $userId . '/files', '', $path);
389+
$path = rtrim($path, '/');
390+
$childPathTemplate = $this->getQueryBuilder()->getConnection()->escapeLikeParameter($path) . '/_%';
391+
392+
$qb->limitToFileTargetLike($childPathTemplate, $childAlias);
388393
} else {
389-
$qb->limitToFileTarget($path, $childAlias);
394+
$nonChildPath = $path === '' ? '/' : $path;
395+
$qb->limitToFileTarget($nonChildPath, $childAlias);
390396
}
391397

392398
$qb->chunk($probe->getItemsOffset(), $probe->getItemsLimit());

0 commit comments

Comments
 (0)