Skip to content

Commit 4bc8601

Browse files
juliusknorrnickvergessen
authored andcommitted
Return proper status when file didn't exist before
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent e9bd87a commit 4bc8601

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

apps/dav/lib/Upload/ChunkingPlugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace OCA\DAV\Upload;
2424

25+
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
2526
use Sabre\DAV\Exception\BadRequest;
2627
use Sabre\DAV\Server;
2728
use Sabre\DAV\ServerPlugin;
@@ -68,6 +69,7 @@ function beforeMove($sourcePath, $destination) {
6869
* @return bool|void false to stop handling, void to skip this handler
6970
*/
7071
public function performMove($path, $destination) {
72+
$fileExists = $this->server->tree->nodeExists($destination);
7173
// do a move manually, skipping Sabre's default "delete" for existing nodes
7274
try {
7375
$this->server->tree->move($path, $destination);
@@ -86,7 +88,7 @@ public function performMove($path, $destination) {
8688

8789
$response = $this->server->httpResponse;
8890
$response->setHeader('Content-Length', '0');
89-
$response->setStatus(204);
91+
$response->setStatus($fileExists ? 204 : 201);
9092

9193
return false;
9294
}

apps/dav/tests/unit/Upload/ChunkingPluginTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ public function testBeforeMoveFutureFileSkipNonExisting() {
100100
->method('nodeExists')
101101
->with('target')
102102
->will($this->returnValue(false));
103-
$this->response->expects($this->never())
104-
->method('setStatus');
103+
$this->response->expects($this->once())
104+
->method('setHeader')
105+
->with('Content-Length', '0');
106+
$this->response->expects($this->once())
107+
->method('setStatus')
108+
->with(201);
105109
$this->request->expects($this->once())
106110
->method('getHeader')
107111
->with('OC-Total-Length')

0 commit comments

Comments
 (0)