From: Bart Visscher Date: Sun, 8 Jul 2012 20:11:13 +0000 (+0200) Subject: Custom chunking support X-Git-Tag: v4.5.0beta1~74^2~225^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e8010209bb1ec8ef9ecc1cff7ac2b2d4d414bd74;p=nextcloud-server.git Custom chunking support --- diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index b75bb5c50f5..894256d5b2a 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -33,10 +33,31 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa * @return void */ public function createFile($name, $data = null) { - - $newPath = $this->path . '/' . $name; - OC_Filesystem::file_put_contents($newPath,$data); - + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { + $cache = new OC_Cache_File(); + $cache->set($name, $data); + preg_match('/(?P.*)-chunking-(?P\d+)-(?P\d+)-(?P\d+)/', $name, $matches); + $prefix = $matches['name'].'-chunking-'.$matches['transferid'].'-'.$matches['chunkcount'].'-'; + $parts = 0; + for($i=0; $i < $matches['chunkcount']; $i++) { + if ($cache->hasKey($prefix.$i)) { + $parts ++; + } + } + if ($parts == $matches['chunkcount']) { + $newPath = $this->path . '/' . $matches['name']; + $f = OC_Filesystem::fopen($newPath, 'w'); + for($i=0; $i < $matches['chunkcount']; $i++) { + $chunk = $cache->get($prefix.$i); + $cache->remove($prefix.$i); + fwrite($f,$chunk); + } + fclose($f); + } + } else { + $newPath = $this->path . '/' . $name; + OC_Filesystem::file_put_contents($newPath,$data); + } } /**