Skip to content

Commit

Permalink
Merge pull request #28795 from owncloud/newdav-directchunk
Browse files Browse the repository at this point in the history
Store new dav chunks directly, no hooks
  • Loading branch information
Vincent Petry authored Aug 28, 2017
2 parents 20094dd + 44e72ac commit fb43344
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
10 changes: 10 additions & 0 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,14 @@ public function moveInto($targetName, $fullSourcePath, INode $sourceNode) {

return true;
}

/**
* Create a file directly, bypassing the hooks
*
* @param string $name name
* @param resource $data data
*/
public function createFileDirectly($name, $data) {
$this->fileView->file_put_contents($this->getPath() . '/' . $name, $data);
}
}
1 change: 0 additions & 1 deletion apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,4 @@ protected function sanitizeMtime ($mtimeFromRequest) {
}
return $mtime;
}

}
4 changes: 2 additions & 2 deletions apps/dav/lib/Upload/UploadFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function __construct(Directory $node) {
}

function createFile($name, $data = null) {
// TODO: verify name - should be a simple number
$this->node->createFile($name, $data);
// need to bypass hooks for individual chunks
$this->node->createFileDirectly($name, $data);
}

function createDirectory($name) {
Expand Down
59 changes: 23 additions & 36 deletions tests/integration/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,55 +859,42 @@ public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id)
}

/**
* @Given user :user uploads new chunk file :num with :data to id :id with checksum :checksum
* @Given user :user moves new chunk file with id :id to :dest
*/
public function userUploadsNewChunkFileOfWithToIdWithChecksum($user, $num, $data, $id, $checksum)
{
try {
$data = \GuzzleHttp\Stream\Stream::factory($data);
$destination = '/uploads/' . $user . '/' . $id . '/' . $num;
$this->makeDavRequest(
$user,
'PUT',
$destination,
['OC-Checksum' => $checksum],
$data,
"uploads"
);
} catch (\GuzzleHttp\Exception\BadResponseException $ex) {
$this->response = $ex->getResponse();
}
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest) {
$this->moveNewDavChunkToFinalFile($user, $id, $dest, []);
}

/**
* @Given user :user moves new chunk file with id :id to :dest
* @Then user :user moves new chunk file with id :id to :dest with size :size
*/
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest)
{
try {
$source = '/uploads/' . $user . '/' . $id . '/.file';
$destination = $this->baseUrlWithoutOCSAppendix() . $this->getDavFilesPath($user) . $dest;
$this->makeDavRequest($user, 'MOVE', $source, [
'Destination' => $destination
], null, "uploads");
} catch (\GuzzleHttp\Exception\RequestException $ex) {
$this->response = $ex->getResponse();
}
public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $dest, $size) {
$this->moveNewDavChunkToFinalFile($user, $id, $dest, ['OC-Total-Length' => $size]);
}

/**
* @Then user :user moves new chunk file with id :id to :dest with size :size
* @Then user :user moves new chunk file with id :id to :dest with checksum :checksum
*/
public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $dest, $size)
{
public function userMovesNewChunkFileWithIdToMychunkedfileWithChecksum($user, $id, $dest, $checksum) {
$this->moveNewDavChunkToFinalFile($user, $id, $dest, ['OC-Checksum' => $checksum]);
}

/**
* Move chunked new dav file to final file
*
* @param string $user user
* @param string $id upload id
* @param string $dest destination path
* @param array $headers extra headers
*/
private function moveNewDavChunkToFinalFile($user, $id, $dest, $headers) {
$source = '/uploads/' . $user . '/' . $id . '/.file';
$destination = $this->baseUrlWithoutOCSAppendix() . $this->getDavFilesPath($user) . $dest;

$headers['Destination'] = $destination;

try {
$this->response = $this->makeDavRequest($user, 'MOVE', $source, [
'Destination' => $destination,
'OC-Total-Length' => $size
], null, "uploads");
$this->response = $this->makeDavRequest($user, 'MOVE', $source, $headers, null, "uploads");
} catch(\GuzzleHttp\Exception\BadResponseException $ex) {
$this->response = $ex->getResponse();
}
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/features/checksums.feature
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,22 @@ Feature: checksums
When user "user0" downloads the file "/local_storage/prueba_cksum.txt"
Then The header checksum should match "SHA1:a35b7605c8f586d735435535c337adc066c2ccb6"

Scenario: Upload chunked file where checksum does not match
Scenario: Upload new dav chunked file where checksum matches
Given using new dav path
And user "user0" exists
And user "user0" creates a new chunking upload with id "chunking-42"
And user "user0" uploads new chunk file "2" with "BBBBB" to id "chunking-42"
And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42" with checksum "SHA1:f005ba11"
And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42"
And user "user0" moves new chunk file with id "chunking-42" to "/myChunkedFile.txt" with checksum "SHA1:5d84d61b03fdacf813640f5242d309721e0629b1"
Then the HTTP status code should be "201"

Scenario: Upload new dav chunked file where checksum does not match
Given using new dav path
And user "user0" exists
And user "user0" creates a new chunking upload with id "chunking-42"
And user "user0" uploads new chunk file "2" with "BBBBB" to id "chunking-42"
And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42"
And user "user0" moves new chunk file with id "chunking-42" to "/myChunkedFile.txt" with checksum "SHA1:f005ba11"
Then the HTTP status code should be "400"

Scenario: Upload a file where checksum does not match
Expand Down

0 comments on commit fb43344

Please sign in to comment.