diff options
Diffstat (limited to 'lib/filechunking.php')
-rw-r--r-- | lib/filechunking.php | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/lib/filechunking.php b/lib/filechunking.php index d03af226d8b..5ab33c77ad7 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; + } + } + } } |