summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-16 10:48:21 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-16 10:48:21 +0200
commit39599019e5c3e47c5d03a1b63b438cacdab5b37e (patch)
tree0a0fe37452a13b004513451121efeb44181cbc45
parent16ef5a8b357e623b1f1621c3e52957167e93e46b (diff)
downloadnextcloud-server-39599019e5c3e47c5d03a1b63b438cacdab5b37e.tar.gz
nextcloud-server-39599019e5c3e47c5d03a1b63b438cacdab5b37e.zip
adding detection of aborted uploads
-rw-r--r--lib/connector/sabre/directory.php99
1 files changed, 58 insertions, 41 deletions
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index 3181a4b310f..8a092c2455a 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -55,53 +55,40 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
- $info = OC_FileChunking::decodeName($name);
- if (empty($info)) {
- throw new Sabre_DAV_Exception_NotImplemented();
- }
- $chunk_handler = new OC_FileChunking($info);
- $chunk_handler->store($info['index'], $data);
- if ($chunk_handler->isComplete()) {
- $newPath = $this->path . '/' . $info['name'];
- $chunk_handler->file_assemble($newPath);
- return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
- }
- } else {
- $newPath = $this->path . '/' . $name;
-
- // mark file as partial while uploading (ignored by the scanner)
- $partpath = $newPath . '.part';
-
- \OC\Files\Filesystem::file_put_contents($partpath, $data);
-
- //detect aborted upload
- if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
- if (isset($_SERVER['CONTENT_LENGTH'])) {
- $expected = $_SERVER['CONTENT_LENGTH'];
- $actual = \OC\Files\Filesystem::filesize($partpath);
- if ($actual != $expected) {
- \OC\Files\Filesystem::unlink($partpath);
- throw new Sabre_DAV_Exception_BadRequest(
- 'expected filesize ' . $expected . ' got ' . $actual);
- }
- }
- }
+ return $this->createFileChunked($name, $data);
+ }
+ $newPath = $this->path . '/' . $name;
+
+ // mark file as partial while uploading (ignored by the scanner)
+ $partpath = $newPath . '.part';
- // rename to correct path
- \OC\Files\Filesystem::rename($partpath, $newPath);
+ \OC\Files\Filesystem::file_put_contents($partpath, $data);
- // allow sync clients to send the mtime along in a header
- $mtime = OC_Request::hasModificationTime();
- if ($mtime !== false) {
- if(\OC\Files\Filesystem::touch($newPath, $mtime)) {
- header('X-OC-MTime: accepted');
+ //detect aborted upload
+ if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
+ if (isset($_SERVER['CONTENT_LENGTH'])) {
+ $expected = $_SERVER['CONTENT_LENGTH'];
+ $actual = \OC\Files\Filesystem::filesize($partpath);
+ if ($actual != $expected) {
+ \OC\Files\Filesystem::unlink($partpath);
+ throw new Sabre_DAV_Exception_BadRequest(
+ 'expected filesize ' . $expected . ' got ' . $actual);
}
}
+ }
- return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
+ // rename to correct path
+ \OC\Files\Filesystem::rename($partpath, $newPath);
+
+ // allow sync clients to send the mtime along in a header
+ $mtime = OC_Request::hasModificationTime();
+ if ($mtime !== false) {
+ if(\OC\Files\Filesystem::touch($newPath, $mtime)) {
+ header('X-OC-MTime: accepted');
+ }
}
- return null;
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
/**
@@ -250,7 +237,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* If the array is empty, all properties should be returned
*
* @param array $properties
- * @return void
+ * @return array
*/
public function getProperties($properties) {
$props = parent::getProperties($properties);
@@ -260,4 +247,34 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
return $props;
}
+
+ private function createFileChunked($name, $data)
+ {
+ $info = OC_FileChunking::decodeName($name);
+ if (empty($info)) {
+ throw new Sabre_DAV_Exception_NotImplemented();
+ }
+ $chunk_handler = new OC_FileChunking($info);
+ $bytesWritten = $chunk_handler->store($info['index'], $data);
+
+ //detect aborted upload
+ if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
+ if (isset($_SERVER['CONTENT_LENGTH'])) {
+ $expected = $_SERVER['CONTENT_LENGTH'];
+ if ($bytesWritten != $expected) {
+ $chunk_handler->cleanup();
+ throw new Sabre_DAV_Exception_BadRequest(
+ 'expected filesize ' . $expected . ' got ' . $bytesWritten);
+ }
+ }
+ }
+
+ if ($chunk_handler->isComplete()) {
+ $newPath = $this->path . '/' . $info['name'];
+ $chunk_handler->file_assemble($newPath);
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
+ }
+
+ return null;
+ }
}