Skip to content
Merged
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
Next Next commit
fix(files): Limit transferring incoming shares to the selected path
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Jul 1, 2025
commit 918473d7f2e5d8b0f16997724d153ca0d2fd30d3
38 changes: 23 additions & 15 deletions apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
namespace OCA\Files\Service;

use Closure;
use Exception;
use OC\Files\Filesystem;
use OC\Files\View;
use OC\User\NoUserException;
use OCA\Encryption\Util;
use OCA\Files\Exception\TransferOwnershipException;
use OCP\Encryption\IManager as IEncryptionManager;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\IHomeStorage;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -158,13 +160,12 @@ public function transfer(
$sourceShares = $this->collectIncomingShares(
$sourceUid,
$output,
$view
$sourcePath,
);
$destinationShares = $this->collectIncomingShares(
$destinationUid,
$output,
$view,
true
null,
);
$this->transferIncomingShares(
$sourceUid,
Expand Down Expand Up @@ -333,7 +334,7 @@ private function collectUsersShares(
return mb_strpos(
Filesystem::normalizePath($relativePath . '/', false),
$normalizedPath . '/') === 0;
} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}
});
Expand Down Expand Up @@ -361,14 +362,16 @@ private function collectUsersShares(
}, $shares)));
}

private function collectIncomingShares(string $sourceUid,
private function collectIncomingShares(
string $sourceUid,
OutputInterface $output,
View $view,
bool $addKeys = false): array {
?string $path,
): array {
$output->writeln("Collecting all incoming share information for files and folders of $sourceUid ...");

$shares = [];
$progress = new ProgressBar($output);
$normalizedPath = Filesystem::normalizePath($path);

$offset = 0;
while (true) {
Expand All @@ -377,14 +380,19 @@ private function collectIncomingShares(string $sourceUid,
if (empty($sharePage)) {
break;
}
if ($addKeys) {
foreach ($sharePage as $singleShare) {
$shares[$singleShare->getNodeId()] = $singleShare;
}
} else {
foreach ($sharePage as $singleShare) {
$shares[] = $singleShare;
}

if ($path !== null && $path !== "$sourceUid/files") {
$sharePage = array_filter($sharePage, static function (IShare $share) use ($sourceUid, $normalizedPath) {
try {
return str_starts_with(Filesystem::normalizePath($sourceUid . '/files' . $share->getTarget() . '/', false), $normalizedPath . '/');
} catch (Exception) {
return false;
}
});
}

foreach ($sharePage as $share) {
$shares[$share->getNodeId()] = $share;
}

$offset += 50;
Expand Down