Skip to content

Commit

Permalink
Fix cache update when doing a rename that overwrites the target
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Feb 27, 2015
1 parent 8abb80c commit fc027bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/private/files/cache/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function propagate($path, $time = null) {
* @param int $time
*/
public function update($path, $time = null) {
if(Scanner::isPartialFile($path)) {
if (Scanner::isPartialFile($path)) {
return;
}
/**
Expand Down Expand Up @@ -116,6 +116,9 @@ public function rename($source, $target) {
if ($sourceStorage && $targetStorage) {
if ($sourceStorage === $targetStorage) {
$cache = $sourceStorage->getCache($sourceInternalPath);
if ($cache->inCache($targetInternalPath)) {
$cache->remove($targetInternalPath);
}
$cache->move($sourceInternalPath, $targetInternalPath);

if (pathinfo($sourceInternalPath, PATHINFO_EXTENSION) !== pathinfo($targetInternalPath, PATHINFO_EXTENSION)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/files/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,4 +962,17 @@ function directoryTraversalProvider() {
public function testConstructDirectoryTraversalException($root) {
new \OC\Files\View($root);
}

public function testRenameOverWrite() {
$storage = new Temporary(array());
$scanner = $storage->getScanner();
$storage->mkdir('sub');
$storage->mkdir('foo');
$storage->file_put_contents('foo.txt', 'asd');
$storage->file_put_contents('foo/bar.txt', 'asd');
$scanner->scan('');
\OC\Files\Filesystem::mount($storage, array(), '/test/');
$view = new \OC\Files\View('');
$this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt'));
}
}

0 comments on commit fc027bc

Please sign in to comment.