summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-24 15:14:42 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-24 15:14:42 +0200
commit4e7f82ef04b3713c71b4c2a2732892490e42e0d4 (patch)
tree1858adc95999e1c6a4171a150eb11d242ec0cf62
parentcf9dbc6e349bc287a414547944fd2a6dff383d64 (diff)
downloadnextcloud-server-4e7f82ef04b3713c71b4c2a2732892490e42e0d4.tar.gz
nextcloud-server-4e7f82ef04b3713c71b4c2a2732892490e42e0d4.zip
unify duplicate code
-rw-r--r--lib/connector/sabre/directory.php56
-rw-r--r--lib/connector/sabre/file.php32
2 files changed, 29 insertions, 59 deletions
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index 0717d952268..fa20a60f3a5 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -54,59 +54,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
throw new \Sabre_DAV_Exception_Forbidden();
}
- 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';
-
- $putOkay = \OC\Files\Filesystem::file_put_contents($partpath, $data);
- if ($putOkay === false) {
- \OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR);
- \OC\Files\Filesystem::unlink($partpath);
- throw new Sabre_DAV_Exception();
- }
-
- //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
- \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 OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
- }
-
- return null;
+ $path = $this->path . '/' . $name;
+ $node = new OC_Connector_Sabre_File($path);
+ return $node->put($data);
}
/**
diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 57ba94c7b19..aa71b8be217 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -46,7 +46,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function put($data) {
- if (!\OC\Files\Filesystem::isUpdatable($this->path)) {
+ if (\OC\Files\Filesystem::file_exists($this->path) &&
+ !\OC\Files\Filesystem::isUpdatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
@@ -54,7 +55,26 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if (\OC_Util::encryptedFiles()) {
throw new \Sabre_DAV_Exception_ServiceUnavailable();
}
-
+
+ // chunked handling
+ if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
+ list(, $name) = \Sabre_DAV_URLUtil::splitPath($this->path);
+
+ $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);
+ }
+
+ return null;
+ }
+
// mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part';
@@ -66,7 +86,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
}
//detect aborted upload
- if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
+ if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
$actual = \OC\Files\Filesystem::filesize($partpath);
@@ -81,10 +101,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
- //allow sync clients to send the mtime along in a header
+ // allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
- if (\OC\Files\Filesystem::touch($this->path, $mtime)) {
+ if(\OC\Files\Filesystem::touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
}
}
@@ -99,7 +119,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function get() {
- //throw execption if encryption is disabled but files are still encrypted
+ //throw exception if encryption is disabled but files are still encrypted
if (\OC_Util::encryptedFiles()) {
throw new \Sabre_DAV_Exception_ServiceUnavailable();
} else {