Skip to content

Commit 918473d

Browse files
committed
fix(files): Limit transferring incoming shares to the selected path
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 359fe58 commit 918473d

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
namespace OCA\Files\Service;
1111

1212
use Closure;
13+
use Exception;
1314
use OC\Files\Filesystem;
1415
use OC\Files\View;
1516
use OC\User\NoUserException;
1617
use OCA\Encryption\Util;
1718
use OCA\Files\Exception\TransferOwnershipException;
1819
use OCP\Encryption\IManager as IEncryptionManager;
1920
use OCP\Files\Config\IUserMountCache;
21+
use OCP\Files\File;
2022
use OCP\Files\FileInfo;
2123
use OCP\Files\IHomeStorage;
2224
use OCP\Files\InvalidPathException;
@@ -158,13 +160,12 @@ public function transfer(
158160
$sourceShares = $this->collectIncomingShares(
159161
$sourceUid,
160162
$output,
161-
$view
163+
$sourcePath,
162164
);
163165
$destinationShares = $this->collectIncomingShares(
164166
$destinationUid,
165167
$output,
166-
$view,
167-
true
168+
null,
168169
);
169170
$this->transferIncomingShares(
170171
$sourceUid,
@@ -333,7 +334,7 @@ private function collectUsersShares(
333334
return mb_strpos(
334335
Filesystem::normalizePath($relativePath . '/', false),
335336
$normalizedPath . '/') === 0;
336-
} catch (\Exception $e) {
337+
} catch (Exception $e) {
337338
return false;
338339
}
339340
});
@@ -361,14 +362,16 @@ private function collectUsersShares(
361362
}, $shares)));
362363
}
363364

364-
private function collectIncomingShares(string $sourceUid,
365+
private function collectIncomingShares(
366+
string $sourceUid,
365367
OutputInterface $output,
366-
View $view,
367-
bool $addKeys = false): array {
368+
?string $path,
369+
): array {
368370
$output->writeln("Collecting all incoming share information for files and folders of $sourceUid ...");
369371

370372
$shares = [];
371373
$progress = new ProgressBar($output);
374+
$normalizedPath = Filesystem::normalizePath($path);
372375

373376
$offset = 0;
374377
while (true) {
@@ -377,14 +380,19 @@ private function collectIncomingShares(string $sourceUid,
377380
if (empty($sharePage)) {
378381
break;
379382
}
380-
if ($addKeys) {
381-
foreach ($sharePage as $singleShare) {
382-
$shares[$singleShare->getNodeId()] = $singleShare;
383-
}
384-
} else {
385-
foreach ($sharePage as $singleShare) {
386-
$shares[] = $singleShare;
387-
}
383+
384+
if ($path !== null && $path !== "$sourceUid/files") {
385+
$sharePage = array_filter($sharePage, static function (IShare $share) use ($sourceUid, $normalizedPath) {
386+
try {
387+
return str_starts_with(Filesystem::normalizePath($sourceUid . '/files' . $share->getTarget() . '/', false), $normalizedPath . '/');
388+
} catch (Exception) {
389+
return false;
390+
}
391+
});
392+
}
393+
394+
foreach ($sharePage as $share) {
395+
$shares[$share->getNodeId()] = $share;
388396
}
389397

390398
$offset += 50;

0 commit comments

Comments
 (0)