Skip to content

Commit

Permalink
Merge pull request #48968 from nextcloud/backport/47847/stable29
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Oct 29, 2024
2 parents 1f225c2 + a61d2ab commit f99ae33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,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();
}
/**
* @var \OC\Files\Storage\Local $sourceStorage
Expand All @@ -629,11 +631,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 @@ -22,6 +22,8 @@

namespace Test\Files\Storage;

use OC\Files\Storage\Wrapper\Jail;

/**
* Class LocalTest
*
Expand Down Expand Up @@ -150,4 +152,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'));
}
}

0 comments on commit f99ae33

Please sign in to comment.