Merge pull request #22239 from nextcloud/backport/22128/stable19
[stable19] Delete chunks if the move on an upload failed
This commit is contained in:
commit
fef5925ed4
|
@ -26,6 +26,7 @@
|
||||||
namespace OCA\DAV\Upload;
|
namespace OCA\DAV\Upload;
|
||||||
|
|
||||||
use OCA\DAV\Connector\Sabre\Directory;
|
use OCA\DAV\Connector\Sabre\Directory;
|
||||||
|
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
|
||||||
use Sabre\DAV\Exception\BadRequest;
|
use Sabre\DAV\Exception\BadRequest;
|
||||||
use Sabre\DAV\Exception\NotFound;
|
use Sabre\DAV\Exception\NotFound;
|
||||||
use Sabre\DAV\INode;
|
use Sabre\DAV\INode;
|
||||||
|
@ -87,13 +88,17 @@ class ChunkingPlugin extends ServerPlugin {
|
||||||
* @return bool|void false to stop handling, void to skip this handler
|
* @return bool|void false to stop handling, void to skip this handler
|
||||||
*/
|
*/
|
||||||
public function performMove($path, $destination) {
|
public function performMove($path, $destination) {
|
||||||
if (!$this->server->tree->nodeExists($destination)) {
|
$fileExists = $this->server->tree->nodeExists($destination);
|
||||||
// skip and let the default handler do its work
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// do a move manually, skipping Sabre's default "delete" for existing nodes
|
// do a move manually, skipping Sabre's default "delete" for existing nodes
|
||||||
$this->server->tree->move($path, $destination);
|
try {
|
||||||
|
$this->server->tree->move($path, $destination);
|
||||||
|
} catch (Forbidden $e) {
|
||||||
|
$sourceNode = $this->server->tree->getNodeForPath($path);
|
||||||
|
if ($sourceNode instanceof FutureFile) {
|
||||||
|
$sourceNode->delete();
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
// trigger all default events (copied from CorePlugin::move)
|
// trigger all default events (copied from CorePlugin::move)
|
||||||
$this->server->emit('afterMove', [$path, $destination]);
|
$this->server->emit('afterMove', [$path, $destination]);
|
||||||
|
@ -102,7 +107,7 @@ class ChunkingPlugin extends ServerPlugin {
|
||||||
|
|
||||||
$response = $this->server->httpResponse;
|
$response = $this->server->httpResponse;
|
||||||
$response->setHeader('Content-Length', '0');
|
$response->setHeader('Content-Length', '0');
|
||||||
$response->setStatus(204);
|
$response->setStatus($fileExists ? 204 : 201);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,14 +128,18 @@ class ChunkingPluginTest extends TestCase {
|
||||||
->method('nodeExists')
|
->method('nodeExists')
|
||||||
->with('target')
|
->with('target')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
$this->response->expects($this->never())
|
$this->response->expects($this->once())
|
||||||
->method('setStatus');
|
->method('setHeader')
|
||||||
|
->with('Content-Length', '0');
|
||||||
|
$this->response->expects($this->once())
|
||||||
|
->method('setStatus')
|
||||||
|
->with(201);
|
||||||
$this->request->expects($this->once())
|
$this->request->expects($this->once())
|
||||||
->method('getHeader')
|
->method('getHeader')
|
||||||
->with('OC-Total-Length')
|
->with('OC-Total-Length')
|
||||||
->willReturn(4);
|
->willReturn(4);
|
||||||
|
|
||||||
$this->assertNull($this->plugin->beforeMove('source', 'target'));
|
$this->assertFalse($this->plugin->beforeMove('source', 'target'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBeforeMoveFutureFileMoveIt() {
|
public function testBeforeMoveFutureFileMoveIt() {
|
||||||
|
|
Loading…
Reference in New Issue