Merge pull request #24813 from owncloud/delete-ghost-files
allow deleting "ghost files" trough the View and Node api
This commit is contained in:
commit
bf917d7063
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Robin Appelman <icewind@owncloud.com>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
|
||||
|
||||
use OC\Connector\Sabre\Exception\FileLocked;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\Lock\ILockingProvider;
|
||||
|
||||
/**
|
||||
* Class DeleteTest
|
||||
*
|
||||
* @group DB
|
||||
*
|
||||
* @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
|
||||
*/
|
||||
class DeleteTest extends RequestTest {
|
||||
public function testBasicUpload() {
|
||||
$user = $this->getUniqueID();
|
||||
$view = $this->setupUser($user, 'pass');
|
||||
|
||||
$view->file_put_contents('foo.txt', 'asd');
|
||||
$mount = $view->getMount('foo.txt');
|
||||
$internalPath = $view->getAbsolutePath();
|
||||
|
||||
// create a ghost file
|
||||
$mount->getStorage()->unlink($mount->getInternalPath($internalPath));
|
||||
|
||||
// cache entry still exists
|
||||
$this->assertInstanceOf('\OCP\Files\FileInfo', $view->getFileInfo('foo.txt'));
|
||||
|
||||
$response = $this->request($view, $user, 'pass', 'DELETE', '/foo.txt');
|
||||
|
||||
$this->assertEquals(Http::STATUS_NO_CONTENT, $response->getStatus());
|
||||
|
||||
// no longer in the cache
|
||||
$this->assertFalse($view->getFileInfo('foo.txt'));
|
||||
}
|
||||
}
|
|
@ -157,7 +157,7 @@ class Local extends \OC\Files\Storage\Common {
|
|||
|
||||
public function filemtime($path) {
|
||||
clearstatcache($this->getSourcePath($path));
|
||||
return filemtime($this->getSourcePath($path));
|
||||
return $this->file_exists($path) ? filemtime($this->getSourcePath($path)) : false;
|
||||
}
|
||||
|
||||
public function touch($path, $mtime = null) {
|
||||
|
|
|
@ -337,10 +337,17 @@ class View {
|
|||
return $this->removeMount($mount, $absolutePath);
|
||||
}
|
||||
if ($this->is_dir($path)) {
|
||||
return $this->basicOperation('rmdir', $path, array('delete'));
|
||||
$result = $this->basicOperation('rmdir', $path, array('delete'));
|
||||
} else {
|
||||
return false;
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
|
||||
$storage = $mount->getStorage();
|
||||
$internalPath = $mount->getInternalPath($absolutePath);
|
||||
$storage->getUpdater()->remove($internalPath);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -679,7 +686,15 @@ class View {
|
|||
if ($mount and $mount->getInternalPath($absolutePath) === '') {
|
||||
return $this->removeMount($mount, $absolutePath);
|
||||
}
|
||||
return $this->basicOperation('unlink', $path, array('delete'));
|
||||
$result = $this->basicOperation('unlink', $path, array('delete'));
|
||||
if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
|
||||
$storage = $mount->getStorage();
|
||||
$internalPath = $mount->getInternalPath($absolutePath);
|
||||
$storage->getUpdater()->remove($internalPath);
|
||||
return true;
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2444,4 +2444,53 @@ class ViewTest extends \Test\TestCase {
|
|||
$data = $view->getFileInfo('.');
|
||||
$this->assertEquals('', $data->getChecksum());
|
||||
}
|
||||
|
||||
public function testDeleteGhostFile() {
|
||||
$storage = new Temporary(array());
|
||||
$scanner = $storage->getScanner();
|
||||
$cache = $storage->getCache();
|
||||
$storage->file_put_contents('foo.txt', 'bar');
|
||||
\OC\Files\Filesystem::mount($storage, array(), '/test/');
|
||||
$scanner->scan('');
|
||||
|
||||
$storage->unlink('foo.txt');
|
||||
|
||||
$this->assertTrue($cache->inCache('foo.txt'));
|
||||
|
||||
$view = new \OC\Files\View('/test');
|
||||
$rootInfo = $view->getFileInfo('');
|
||||
$this->assertEquals(3, $rootInfo->getSize());
|
||||
$view->unlink('foo.txt');
|
||||
$newInfo = $view->getFileInfo('');
|
||||
|
||||
$this->assertFalse($cache->inCache('foo.txt'));
|
||||
$this->assertNotEquals($rootInfo->getEtag(), $newInfo->getEtag());
|
||||
$this->assertEquals(0, $newInfo->getSize());
|
||||
}
|
||||
|
||||
public function testDeleteGhostFolder() {
|
||||
$storage = new Temporary(array());
|
||||
$scanner = $storage->getScanner();
|
||||
$cache = $storage->getCache();
|
||||
$storage->mkdir('foo');
|
||||
$storage->file_put_contents('foo/foo.txt', 'bar');
|
||||
\OC\Files\Filesystem::mount($storage, array(), '/test/');
|
||||
$scanner->scan('');
|
||||
|
||||
$storage->rmdir('foo');
|
||||
|
||||
$this->assertTrue($cache->inCache('foo'));
|
||||
$this->assertTrue($cache->inCache('foo/foo.txt'));
|
||||
|
||||
$view = new \OC\Files\View('/test');
|
||||
$rootInfo = $view->getFileInfo('');
|
||||
$this->assertEquals(3, $rootInfo->getSize());
|
||||
$view->rmdir('foo');
|
||||
$newInfo = $view->getFileInfo('');
|
||||
|
||||
$this->assertFalse($cache->inCache('foo'));
|
||||
$this->assertFalse($cache->inCache('foo/foo.txt'));
|
||||
$this->assertNotEquals($rootInfo->getEtag(), $newInfo->getEtag());
|
||||
$this->assertEquals(0, $newInfo->getSize());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue