Skip to content

Commit

Permalink
Return proper status when file didn't exist before
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl authored and nickvergessen committed Aug 19, 2020
1 parent e9bd87a commit 4bc8601
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/dav/lib/Upload/ChunkingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,7 @@ function beforeMove($sourcePath, $destination) {
* @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);
Expand All @@ -86,7 +88,7 @@ public function performMove($path, $destination) {

$response = $this->server->httpResponse;
$response->setHeader('Content-Length', '0');
$response->setStatus(204);
$response->setStatus($fileExists ? 204 : 201);

return false;
}
Expand Down
8 changes: 6 additions & 2 deletions apps/dav/tests/unit/Upload/ChunkingPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ public function testBeforeMoveFutureFileSkipNonExisting() {
->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')
Expand Down

0 comments on commit 4bc8601

Please sign in to comment.