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 8ca51376049952c87adae63c8d39f3394e10f35b
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,12 +10,14 @@
namespace OCA\Files\Service;

use Closure;
use Exception;
use OC\Encryption\Manager as EncryptionManager;
use OC\Files\Filesystem;
use OC\Files\View;
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 @@ -159,13 +161,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 @@ -334,7 +335,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 @@ -362,14 +363,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);

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 1 of OC\Files\Filesystem::normalizePath cannot be null, possibly null value provided

$offset = 0;
while (true) {
Expand All @@ -378,14 +381,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