Return proper status when file didn't exist before

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-08-13 15:26:42 +02:00 committed by Joas Schilling
parent e9bd87af96
commit 4bc8601eb2
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
2 changed files with 9 additions and 3 deletions

View file

@ -22,6 +22,7 @@
namespace OCA\DAV\Upload;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
@ -68,6 +69,7 @@ class ChunkingPlugin extends ServerPlugin {
* @return bool|void false to stop handling, void to skip this handler
*/
public function performMove($path, $destination) {
$fileExists = $this->server->tree->nodeExists($destination);
// do a move manually, skipping Sabre's default "delete" for existing nodes
try {
$this->server->tree->move($path, $destination);
@ -86,7 +88,7 @@ class ChunkingPlugin extends ServerPlugin {
$response = $this->server->httpResponse;
$response->setHeader('Content-Length', '0');
$response->setStatus(204);
$response->setStatus($fileExists ? 204 : 201);
return false;
}

View file

@ -100,8 +100,12 @@ class ChunkingPluginTest extends TestCase {
->method('nodeExists')
->with('target')
->will($this->returnValue(false));
$this->response->expects($this->never())
->method('setStatus');
$this->response->expects($this->once())
->method('setHeader')
->with('Content-Length', '0');
$this->response->expects($this->once())
->method('setStatus')
->with(201);
$this->request->expects($this->once())
->method('getHeader')
->with('OC-Total-Length')