rollback cache rename if trashbin move fails
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
c567b1d6b2
commit
b6a600e653
|
@ -278,6 +278,8 @@ class Trashbin {
|
||||||
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
||||||
[$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
|
[$sourceStorage, $sourceInternalPath] = $ownerView->resolvePath('/files/' . $ownerPath);
|
||||||
|
|
||||||
|
$connection = \OC::$server->getDatabaseConnection();
|
||||||
|
$connection->beginTransaction();
|
||||||
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
|
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -300,9 +302,12 @@ class Trashbin {
|
||||||
} else {
|
} else {
|
||||||
$sourceStorage->unlink($sourceInternalPath);
|
$sourceStorage->unlink($sourceInternalPath);
|
||||||
}
|
}
|
||||||
|
$connection->rollBack();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$connection->commit();
|
||||||
|
|
||||||
if ($moveSuccessful) {
|
if ($moveSuccessful) {
|
||||||
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
||||||
$result = $query->execute([$filename, $timestamp, $location, $owner]);
|
$result = $query->execute([$filename, $timestamp, $location, $owner]);
|
||||||
|
|
|
@ -1167,13 +1167,8 @@ class ViewTest extends \Test\TestCase {
|
||||||
->setMethods(['fopen'])
|
->setMethods(['fopen'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$storage2->expects($this->any())
|
$storage2->method('writeStream')
|
||||||
->method('fopen')
|
->willReturn(0);
|
||||||
->willReturnCallback(function ($path, $mode) use ($storage2) {
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */
|
|
||||||
$source = fopen($storage2->getSourcePath($path), $mode);
|
|
||||||
return Quota::wrap($source, 9);
|
|
||||||
});
|
|
||||||
|
|
||||||
$storage1->mkdir('sub');
|
$storage1->mkdir('sub');
|
||||||
$storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');
|
$storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');
|
||||||
|
|
Loading…
Reference in New Issue