From d2332f60f31600641189f03bdecaa82a0f889da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 10 Feb 2013 11:05:43 +0100 Subject: [PATCH 1/7] add a custom header clients can use to skip a n additional propset request --- lib/connector/sabre/file.php | 6 ++++++ lib/request.php | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 521c5f0571..63c581f30c 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -52,6 +52,12 @@ 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 + $mtime = OC_Request::hasModificationTime(); + if ($mtime !== false) { + \OC\Files\Filesystem::touch($this->path,$mtime); + } return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path); } diff --git a/lib/request.php b/lib/request.php index 1661a1406c..3c668b02c5 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; + } + } } From 2644003bf1f82eb812981d27237ec0ce4e026604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 10 Feb 2013 11:44:34 +0100 Subject: [PATCH 2/7] send back 'X-OC-MTime: accepted' when X-OC-MTime was applied --- lib/connector/sabre/file.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 63c581f30c..279615b923 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -56,7 +56,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D //allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { - \OC\Files\Filesystem::touch($this->path,$mtime); + if(\OC\Files\Filesystem::touch($this->path, $mtime)) { + header('X-OC-MTime: accepted'); + } } return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path); From 72a2075b1c25409a2bccde62809eff76812b9a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 11 Feb 2013 09:43:26 +0100 Subject: [PATCH 3/7] readd renaming and mtime handling to new directory nodes --- lib/connector/sabre/directory.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index c4062170d5..d8d74b922a 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -62,7 +62,23 @@ 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); + + // 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); } From 806522d0073cecb2c72ec41f7ae5009024fb7512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 10 Feb 2013 16:18:52 +0100 Subject: [PATCH 4/7] also rename file when it has not been present before --- lib/connector/sabre/directory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index d8d74b922a..6465dcbac3 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -65,9 +65,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa // mark file as partial while uploading (ignored by the scanner) $partpath = $newPath . '.part'; - + \OC\Files\Filesystem::file_put_contents($partpath, $data); - + // rename to correct path \OC\Files\Filesystem::rename($partpath, $newPath); From 15ab2fd52aa3d2971682406a0add82ba453f82f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 10 Feb 2013 17:09:31 +0100 Subject: [PATCH 5/7] check Content-Length to detect aborted uploads --- lib/connector/sabre/directory.php | 10 ++++++++++ lib/connector/sabre/file.php | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 6465dcbac3..a5676d656e 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -68,6 +68,16 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa \OC\Files\Filesystem::file_put_contents($partpath, $data); + //detect aborted upload + if (isset($_SERVER['CONTENT_LENGTH']) + && \OC\Files\Filesystem::filesize($partpath) != $_SERVER['CONTENT_LENGTH']) + { + throw new Sabre_DAV_Exception_BadRequest( + 'expected filesize ' . $_SERVER['CONTENT_LENGTH']. + ' got ' . \OC\Files\Filesystem::filesize($partpath) + ); + } + // rename to correct path \OC\Files\Filesystem::rename($partpath, $newPath); diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 279615b923..ab342fa2c6 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -50,6 +50,15 @@ 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['CONTENT_LENGTH']) + && \OC\Files\Filesystem::filesize($partpath) != $_SERVER['CONTENT_LENGTH']) + { + throw new Sabre_DAV_Exception_BadRequest( + 'expected filesize ' . $_SERVER['CONTENT_LENGTH']. + ' got ' . \OC\Files\Filesystem::filesize($partpath) + ); + } // rename to correct path \OC\Files\Filesystem::rename($partpath, $this->path); From 2cb2991c049387290d6ba71a08381aeac4de2fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 10 Feb 2013 18:17:10 +0100 Subject: [PATCH 6/7] delete partial file when file upload is aborted --- lib/connector/sabre/directory.php | 15 ++++++++------- lib/connector/sabre/file.php | 16 +++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index a5676d656e..f924511535 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -69,13 +69,14 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa \OC\Files\Filesystem::file_put_contents($partpath, $data); //detect aborted upload - if (isset($_SERVER['CONTENT_LENGTH']) - && \OC\Files\Filesystem::filesize($partpath) != $_SERVER['CONTENT_LENGTH']) - { - throw new Sabre_DAV_Exception_BadRequest( - 'expected filesize ' . $_SERVER['CONTENT_LENGTH']. - ' got ' . \OC\Files\Filesystem::filesize($partpath) - ); + 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 diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index ab342fa2c6..e5436f0ad1 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -51,14 +51,16 @@ 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['CONTENT_LENGTH']) - && \OC\Files\Filesystem::filesize($partpath) != $_SERVER['CONTENT_LENGTH']) - { - throw new Sabre_DAV_Exception_BadRequest( - 'expected filesize ' . $_SERVER['CONTENT_LENGTH']. - ' got ' . \OC\Files\Filesystem::filesize($partpath) - ); + 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); From 99f41de7de4e96f5d490cfc8f3b962171d201587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 11 Feb 2013 10:31:01 +0100 Subject: [PATCH 7/7] only check content lenght on PUT to make litmus happy --- lib/connector/sabre/directory.php | 16 +++++++++------- lib/connector/sabre/file.php | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index f924511535..e29059d039 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -69,13 +69,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa \OC\Files\Filesystem::file_put_contents($partpath, $data); //detect aborted upload - 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); + 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); + } } } diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index e5436f0ad1..61165d9956 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -51,13 +51,15 @@ 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['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); + 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); + } } }