summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/connector/sabre/directory.php31
-rw-r--r--lib/connector/sabre/file.php21
-rwxr-xr-xlib/request.php12
3 files changed, 63 insertions, 1 deletions
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index c4062170d5e..e29059d0395 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -62,7 +62,36 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
} else {
$newPath = $this->path . '/' . $name;
- \OC\Files\Filesystem::file_put_contents($newPath, $data);
+
+ // 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);
+ }
+ }
+ }
+
+ // 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);
}
diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 521c5f0571d..61165d9956d 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -50,8 +50,29 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
\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);
+ }
+ }
+ }
+
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
+
+ //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)) {
+ header('X-OC-MTime: accepted');
+ }
+ }
return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
}
diff --git a/lib/request.php b/lib/request.php
index 1661a1406ca..3c668b02c5f 100755
--- a/lib/request.php
+++ b/lib/request.php
@@ -149,4 +149,16 @@ class OC_Request {
return 'gzip';
return false;
}
+
+ /**
+ * @brief Check if the requester sent along an mtime
+ * @returns false or an mtime
+ */
+ static public function hasModificationTime () {
+ if (isset($_SERVER['HTTP_X_OC_MTIME'])) {
+ return $_SERVER['HTTP_X_OC_MTIME'];
+ } else {
+ return false;
+ }
+ }
}