From 703aff6c3508624c22f88a07599c81fec6f7c11e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 18 Sep 2012 18:34:39 +0200 Subject: [PATCH] Run proxies and emit signals when finising chunked upload Otherwise the file cache and the quota isn't checked --- lib/connector/sabre/directory.php | 3 +- lib/filechunking.php | 58 +++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index b5049d800c..bbc615c0b1 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -57,8 +57,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $chunk_handler->store($info['index'], $data); if ($chunk_handler->isComplete()) { $newPath = $this->path . '/' . $info['name']; - $f = OC_Filesystem::fopen($newPath, 'w'); - $chunk_handler->assemble($f); + $chunk_handler->file_assemble($newPath); return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } } else { diff --git a/lib/filechunking.php b/lib/filechunking.php index d03af226d8..5ab33c77ad 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -55,12 +55,13 @@ class OC_FileChunking { public function assemble($f) { $cache = $this->getCache(); $prefix = $this->getPrefix(); + $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); $cache->remove($prefix.$i); - fwrite($f,$chunk); + $count += fwrite($f,$chunk); } - fclose($f); + return $count; } public function signature_split($orgfile, $input) { @@ -91,4 +92,57 @@ class OC_FileChunking { 'count' => $count, ); } + + public function file_assemble($path) { + $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path)); + $data = ''; + // use file_put_contents as method because that best matches what this function does + if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) { + $path = OC_Filesystem::getView()->getRelativePath($absolutePath); + $exists = OC_Filesystem::file_exists($path); + $run = true; + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + if(!$run) { + return false; + } + $target = OC_Filesystem::fopen($path, 'w'); + if($target) { + $count = $this->assemble($target); + fclose($target); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path) + ); + OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); + return $count > 0; + }else{ + return false; + } + } + } }