Skip to content

Commit

Permalink
fix: explicitly ignore nested mounts when transfering ownership
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Feb 4, 2025
1 parent 1f2e168 commit 2c71693
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function isDeletable($path) {
return $this->deletables[$path];
}

public function rename($path1, $path2) {
public function rename($path1, $path2, array $options = []) {
return $this->canRename;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ protected function transferFiles(string $sourceUid,
$view->mkdir($finalTarget);
$finalTarget = $finalTarget . '/' . basename($sourcePath);
}
if ($view->rename($sourcePath, $finalTarget) === false) {
if ($view->rename($sourcePath, $finalTarget, ['checkSubMounts' => false]) === false) {
throw new TransferOwnershipException("Could not transfer files.", 1);
}
if (!is_dir("$sourceUid/files")) {
Expand Down
2 changes: 1 addition & 1 deletion build/integration/features/transfer-ownership.feature
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Feature: transfer-ownership
And user "user2" accepts last share
When transferring ownership of path "test" from "user0" to "user1"
Then the command failed with exit code 1
And the command output contains the text "Could not transfer files."
And the command error output contains the text "Moving a storage (user0/files/test) into another storage (user1) is not allowed"

Scenario: transferring ownership does not transfer received shares
Given user "user0" exists
Expand Down
12 changes: 9 additions & 3 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,14 @@ public function deleteAll($directory) {
*
* @param string $source source path
* @param string $target target path
* @param array $options
*
* @return bool|mixed
* @throws LockedException
*/
public function rename($source, $target) {
public function rename($source, $target, array $options = []) {
$checkSubMounts = $options['checkSubMounts'] ?? true;

$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));

Expand Down Expand Up @@ -798,13 +801,16 @@ public function rename($source, $target) {
try {
$this->changeLock($target, ILockingProvider::LOCK_EXCLUSIVE, true);

$movedMounts = $mountManager->findIn($this->getAbsolutePath($source));
if ($checkSubMounts) {
$movedMounts = $mountManager->findIn($this->getAbsolutePath($source));
} else {
$movedMounts = [];
}

if ($internalPath1 === '') {
$sourceParentMount = $this->getMount(dirname($source));
$movedMounts[] = $mount1;
$this->validateMountMove($movedMounts, $sourceParentMount, $mount2, !$this->targetIsNotShared($storage2, $internalPath2));

/**
* @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
*/
Expand Down

0 comments on commit 2c71693

Please sign in to comment.