Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copying or moving from shared groupfolders #47847

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,13 @@ private function canDoCrossStorageMove(IStorage $sourceStorage) {
*/
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
if ($this->canDoCrossStorageMove($sourceStorage)) {
if ($sourceStorage->instanceOfStorage(Jail::class)) {
// resolve any jailed paths
while ($sourceStorage->instanceOfStorage(Jail::class)) {
/**
* @var \OC\Files\Storage\Wrapper\Jail $sourceStorage
*/
$sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
$sourceStorage = $sourceStorage->getUnjailedStorage();
Comment on lines +568 to +574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably have that same issue in other places in Nextcloud. How about changing getUnjailedStorage to include that while loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the important part is getting the unjailed path; getting the unjailed storage is just a shortcut to avoid looping through all the wrapped storages (which in fact is how I initially implemented the fix, until I noticed the other code in Common::moveFromStorage) and just "jump" directly to the storage wrapped by each Jail. But getting the unjailed storage is not relevant for the fix; it would work with the original source storage as long as the most internal unjailed path is given (unless I am missing something, of course, but at least in the case of shared groupfolders it would work :-) ).

The problem is that if getUnjailedStorage was changed to include the loop and therefore return the storage wrapped by the most internal Jail then it would not be possible to get its unjailed path, as the reference to that most internal Jail would not be available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, then maybe a getUnjailedPath method?

@icewind1991 do you have an opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a new method than overloading getUnjailedPath but it would be good to have a single place to do this logic yes.

}
/**
* @var \OC\Files\Storage\Local $sourceStorage
Expand All @@ -589,11 +591,13 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
*/
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
if ($this->canDoCrossStorageMove($sourceStorage)) {
if ($sourceStorage->instanceOfStorage(Jail::class)) {
// resolve any jailed paths
while ($sourceStorage->instanceOfStorage(Jail::class)) {
/**
* @var \OC\Files\Storage\Wrapper\Jail $sourceStorage
*/
$sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
$sourceStorage = $sourceStorage->getUnjailedStorage();
}
/**
* @var \OC\Files\Storage\Local $sourceStorage
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/Files/Storage/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Test\Files\Storage;

use OC\Files\Storage\Wrapper\Jail;

/**
* Class LocalTest
*
Expand Down Expand Up @@ -135,4 +137,25 @@ public function testUnavailableNonExternal() {
// no exception thrown
$this->assertNotNull($this->instance);
}

public function testMoveNestedJail(): void {
$this->instance->mkdir('foo');
$this->instance->mkdir('foo/bar');
$this->instance->mkdir('target');
$this->instance->file_put_contents('foo/bar/file.txt', 'foo');
$jail1 = new Jail([
'storage' => $this->instance,
'root' => 'foo'
]);
$jail2 = new Jail([
'storage' => $jail1,
'root' => 'bar'
]);
$jail3 = new Jail([
'storage' => $this->instance,
'root' => 'target'
]);
$jail3->moveFromStorage($jail2, 'file.txt', 'file.txt');
$this->assertTrue($this->instance->file_exists('target/file.txt'));
}
}
Loading