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 moving folders out of a cache jail #5424

Merged
merged 4 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lib/private/Files/Cache/Wrapper/CacheJail.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function filterCacheEntry($entry) {
* get the stored metadata of a file or folder
*
* @param string /int $file
* @return array|false
* @return ICacheEntry|false
*/
public function get($file) {
if (is_string($file) or $file == '') {
Expand Down Expand Up @@ -175,6 +175,16 @@ public function move($source, $target) {
$this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
}

/**
* Get the storage id and path needed for a move
*
* @param string $path
* @return array [$storageId, $internalPath]
*/
protected function getMoveInfo($path) {
return [$this->getNumericStorageId(), $this->getSourcePath($path)];
}

/**
* remove all entries for files that are stored on the storage from the cache
*/
Expand Down
50 changes: 50 additions & 0 deletions tests/lib/Files/Cache/Wrapper/CacheJailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Test\Files\Cache\Wrapper;

use OC\Files\Cache\Wrapper\CacheJail;
use Test\Files\Cache\CacheTest;

/**
Expand Down Expand Up @@ -80,4 +81,53 @@ function testGetIncomplete() {
//not supported
$this->assertTrue(true);
}

function testMoveFromJail() {
$folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');

$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
$this->sourceCache->put('source/foo/bar', $folderData);
$this->sourceCache->put('target', $folderData);

$jail = new CacheJail($this->sourceCache, 'source');

$this->sourceCache->moveFromCache($jail, 'foo', 'target/foo');

$this->assertTrue($this->sourceCache->inCache('target/foo'));
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}

function testMoveToJail() {
$folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');

$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
$this->sourceCache->put('source/foo/bar', $folderData);
$this->sourceCache->put('target', $folderData);

$jail = new CacheJail($this->sourceCache, 'target');

$jail->moveFromCache($this->sourceCache, 'source/foo', 'foo');

$this->assertTrue($this->sourceCache->inCache('target/foo'));
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}

function testMoveBetweenJail() {
$folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');

$this->sourceCache->put('source', $folderData);
$this->sourceCache->put('source/foo', $folderData);
$this->sourceCache->put('source/foo/bar', $folderData);
$this->sourceCache->put('target', $folderData);

$jail = new CacheJail($this->sourceCache, 'target');
$sourceJail = new CacheJail($this->sourceCache, 'source');

$jail->moveFromCache($sourceJail, 'foo', 'foo');

$this->assertTrue($this->sourceCache->inCache('target/foo'));
$this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
}
}