Detect failed deletes in the trashbin

This commit is contained in:
Robin Appelman 2015-01-28 15:35:49 +01:00
parent 2124540d1d
commit d4c4e2a322
2 changed files with 41 additions and 3 deletions

View File

@ -180,6 +180,11 @@ class Trashbin {
}
\OC_FileProxy::$enabled = $proxyStatus;
if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort
$view->unlink($trashPath);
return false;
}
if ($sizeOfAddedFiles !== false) {
$size = $sizeOfAddedFiles;
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");

View File

@ -173,4 +173,37 @@ class Storage extends \Test\TestCase {
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/');
$this->assertEquals(0, count($results));
}
/**
* Delete should fail is the source file cant be deleted
*/
public function testSingleStorageDeleteFail() {
/**
* @var \OC\Files\Storage\Temporary | \PHPUnit_Framework_MockObject_MockObject $storage
*/
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->setConstructorArgs([[]])
->setMethods(['rename', 'unlink'])
->getMock();
$storage->expects($this->any())
->method('rename')
->will($this->returnValue(false));
$storage->expects($this->any())
->method('unlink')
->will($this->returnValue(false));
$cache = $storage->getCache();
Filesystem::mount($storage, [], '/' . $this->user . '/files');
$this->userView->file_put_contents('test.txt', 'foo');
$this->assertTrue($storage->file_exists('test.txt'));
$this->assertFalse($this->userView->unlink('test.txt'));
$this->assertTrue($storage->file_exists('test.txt'));
$this->assertTrue($cache->inCache('test.txt'));
// file should not be in the trashbin
$results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files/');
$this->assertEquals(0, count($results));
}
}