diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-15 11:53:51 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-10-15 11:53:51 +0200 |
commit | 25320f19df017947f31ea156ade061274b5bd691 (patch) | |
tree | 6096ab2633d0b58f594fb5e600638603d85acdc9 /lib | |
parent | 0b8273c76834783461bc186cca69e1a73f2570de (diff) | |
parent | 52501d6ba3da5596975a945ba00ea753f6c7f4e7 (diff) | |
download | nextcloud-server-25320f19df017947f31ea156ade061274b5bd691.tar.gz nextcloud-server-25320f19df017947f31ea156ade061274b5bd691.zip |
Merge branch 'master' into avater_with_encryption
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/cache/file.php | 18 | ||||
-rw-r--r-- | lib/private/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | lib/private/connector/sabre/file.php | 51 | ||||
-rw-r--r-- | lib/private/filechunking.php | 23 | ||||
-rw-r--r-- | lib/private/helper.php | 4 | ||||
-rw-r--r-- | lib/private/user.php | 2 |
6 files changed, 78 insertions, 22 deletions
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php index 2ab914d17b8..b0738d2a92b 100644 --- a/lib/private/cache/file.php +++ b/lib/private/cache/file.php @@ -41,6 +41,24 @@ class File { return $result; } + /** + * Returns the size of the stored/cached data + * + * @param $key + * @return int + */ + public function size($key) { + $result = 0; + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + if ($this->hasKey($key)) { + $storage = $this->getStorage(); + $result = $storage->filesize($key); + } + \OC_FileProxy::$enabled = $proxyStatus; + return $result; + } + public function set($key, $value, $ttl=0) { $storage = $this->getStorage(); $result = false; diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php index d0334780361..c51f84bf67c 100644 --- a/lib/private/connector/sabre/directory.php +++ b/lib/private/connector/sabre/directory.php @@ -71,7 +71,6 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $path = $this->path . '/' . $name; $node = new OC_Connector_Sabre_File($path); return $node->put($data); - } /** @@ -229,4 +228,5 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } return $props; } + } diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 667f7407f75..3402946a136 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -60,23 +60,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D // chunked handling if (isset($_SERVER['HTTP_OC_CHUNKED'])) { - - list($path, $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 = $path . '/' . $info['name']; - $chunk_handler->file_assemble($newPath); - return $this->getETagPropertyForPath($newPath); - } - - return null; + return $this->createFileChunked($data); } // mark file as partial while uploading (ignored by the scanner) @@ -214,4 +198,37 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D return \OC\Files\Filesystem::getMimeType($this->path); } + + private function createFileChunked($data) + { + list($path, $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); + $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 = $path . '/' . $info['name']; + $chunk_handler->file_assemble($newPath); + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); + } + + return null; + } + } diff --git a/lib/private/filechunking.php b/lib/private/filechunking.php index 313a6ee87d2..0dfce696cda 100644 --- a/lib/private/filechunking.php +++ b/lib/private/filechunking.php @@ -34,10 +34,19 @@ class OC_FileChunking { return $this->cache; } + /** + * Stores the given $data under the given $key - the number of stored bytes is returned + * + * @param $index + * @param $data + * @return int + */ public function store($index, $data) { $cache = $this->getCache(); $name = $this->getPrefix().$index; $cache->set($name, $data); + + return $cache->size($name); } public function isComplete() { @@ -58,12 +67,24 @@ class OC_FileChunking { $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); - $cache->remove($prefix.$i); $count += fwrite($f, $chunk); } + + $this->cleanup(); return $count; } + /** + * Removes all chunks which belong to this transmission + */ + public function cleanup() { + $cache = $this->getCache(); + $prefix = $this->getPrefix(); + for($i=0; $i < $this->info['chunkcount']; $i++) { + $cache->remove($prefix.$i); + } + } + public function signature_split($orgfile, $input) { $info = unpack('n', fread($input, 2)); $blocksize = $info[1]; diff --git a/lib/private/helper.php b/lib/private/helper.php index a34640d8e36..1236e748256 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -509,11 +509,11 @@ class OC_Helper { * * @param resource $source * @param resource $target - * @return int the number of bytes copied + * @return array the number of bytes copied and result */ public static function streamCopy($source, $target) { if (!$source or !$target) { - return false; + return array(0, false); } $result = true; $count = 0; diff --git a/lib/private/user.php b/lib/private/user.php index b68786c773c..6b350d4cf1b 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -325,7 +325,7 @@ class OC_User { return $backend->getLogoutAttribute(); } - return "href=" . link_to('', 'index.php') . "?logout=true"; + return 'href="' . link_to('', 'index.php') . '?logout=true"'; } /** |