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-10-14 15:49:26 +0200
commit1f0cca0ce07213d4b8fcec74659c0cda013fe8fa (patch)
tree851f11f32efaf2ae2f97f7dd57456930568fb335
parent73570d497960e5b01fda530d4cc1573c879aa3c7 (diff)
downloadnextcloud-server-1f0cca0ce07213d4b8fcec74659c0cda013fe8fa.tar.gz
nextcloud-server-1f0cca0ce07213d4b8fcec74659c0cda013fe8fa.zip
adding detection of aborted uploads
Conflicts: lib/connector/sabre/directory.php
-rw-r--r--lib/connector/sabre/directory.php107
1 files changed, 64 insertions, 43 deletions
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index 96b9cd06d5b..3488784e928 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -61,60 +61,51 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
throw new \Sabre_DAV_Exception_Forbidden();
}
- $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 {
+ return $this->createFileChunked($name, $data);
+ }
- if (!\OC\Files\Filesystem::isCreatable($this->path)) {
- throw new \Sabre_DAV_Exception_Forbidden();
- }
+ if (!\OC\Files\Filesystem::isCreatable($this->path)) {
+ throw new \Sabre_DAV_Exception_Forbidden();
+ }
- $newPath = $this->path . '/' . $name;
+ $newPath = $this->path . '/' . $name;
- // mark file as partial while uploading (ignored by the scanner)
- $partpath = $newPath . '.part';
+ // mark file as partial while uploading (ignored by the scanner)
+ $partpath = $newPath . '.part';
- \OC\Files\Filesystem::file_put_contents($partpath, $data);
+ \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);
- }
+ //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);
}
}
+ }
- // rename to correct path
- $renameOkay = \OC\Files\Filesystem::rename($partpath, $newPath);
- $fileExists = \OC\Files\Filesystem::file_exists($newPath);
- if ($renameOkay === false || $fileExists === false) {
- \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
- \OC\Files\Filesystem::unlink($partpath);
- throw new Sabre_DAV_Exception();
- }
+ // rename to correct path
+ $renameOkay = \OC\Files\Filesystem::rename($partpath, $newPath);
+ $fileExists = \OC\Files\Filesystem::file_exists($newPath);
+ if ($renameOkay === false || $fileExists === false) {
+ \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
+ \OC\Files\Filesystem::unlink($partpath);
+ throw new Sabre_DAV_Exception();
+ }
- // 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');
- }
+ // 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 OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
- return null;
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
/**
@@ -264,7 +255,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);
@@ -274,4 +265,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;
+ }
}