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] 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);