summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connector/sabre/directory.php3
-rw-r--r--lib/filechunking.php58
2 files changed, 57 insertions, 4 deletions
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index b5049d800c4..bbc615c0b16 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 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;
+ }
+ }
+ }
}