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; } } }
/** * abstraction for running most basic operations * @param string $operation * @param string #path * @param array (optional) hooks * @param mixed (optional) $extraParam * @return mixed */ private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { $absolutePath = $this->getAbsolutePath($path); if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); if ($path == null) { return false; } $internalPath = $this->getInternalPath($path); $run = true; if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) { foreach ($hooks as $hook) { if ($hook != 'read') { OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run)); } else { OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path)); } } } if ($run and $storage = $this->getStorage($path)) { if (!is_null($extraParam)) { $result = $storage->{$operation}($internalPath, $extraParam); } else { $result = $storage->{$operation}($internalPath); } $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) { if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open foreach ($hooks as $hook) { if ($hook != 'read') { OC_Hook::emit(OC_Filesystem::CLASSNAME, 'post_' . $hook, array(OC_Filesystem::signal_param_path => $path)); } } } } return $result; } } return null; }
/** * abstraction for running most basic operations * @param string $operation * @param string #path * @param array (optional) hooks * @param mixed (optional) $extraParam * @return mixed */ private static function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { if (OC_FileProxy::runPreProxies($operation, $path, $extraParam) and self::canRead($path) and $storage = self::getStorage($path)) { $interalPath = self::getInternalPath($path); $run = true; foreach ($hooks as $hook) { if ($hook != 'read') { OC_Hook::emit('OC_Filesystem', $hook, array('path' => $path, 'run' => &$run)); } else { OC_Hook::emit('OC_Filesystem', $hook, array('path' => $path)); } } if ($run) { if ($extraParam) { $result = $storage->{$operation}($interalPath, $extraParam); } else { $result = $storage->{$operation}($interalPath); } $result = OC_FileProxy::runPostProxies($operation, $path, $result); foreach ($hooks as $hook) { if ($hook != 'read') { OC_Hook::emit('OC_Filesystem', 'post_' . $hook, array('path' => $path)); } } return $result; } } return null; }
/** * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage * * @param string $operation * @param string $path * @param array $hooks (optional) * @param mixed $extraParam (optional) * @return mixed * * This method takes requests for basic filesystem functions (e.g. reading & writing * files), processes hooks and proxies, sanitises paths, and finally passes them on to * \OC\Files\Storage\Storage for delegation to a storage backend for execution */ private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { $postFix = substr($path, -1, 1) === '/' ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and Filesystem::isValidPath($path) and !Filesystem::isFileBlacklisted($path)) { $path = $this->getRelativePath($absolutePath); if ($path == null) { return false; } $run = $this->runHooks($hooks, $path); list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); if ($run and $storage) { if (!is_null($extraParam)) { $result = $storage->{$operation}($internalPath, $extraParam); } else { $result = $storage->{$operation}($internalPath); } $result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); if (in_array('delete', $hooks) and $result) { $this->updater->remove($path); } if (in_array('write', $hooks)) { $this->updater->update($path); } if (in_array('touch', $hooks)) { $this->updater->update($path, $extraParam); } if ($this->shouldEmitHooks($path) && $result !== false) { if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open $this->runHooks($hooks, $path, true); } } return $result; } } return null; }
/** * @brief abstraction layer for basic filesystem functions: wrapper for OC_Filestorage * @param string $operation * @param string #path * @param array (optional) hooks * @param mixed (optional) $extraParam * @return mixed * * This method takes requests for basic filesystem functions (e.g. reading & writing * files), processes hooks and proxies, sanitises paths, and finally passes them on to * OC_Filestorage for delegation to a storage backend for execution */ private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) { $postFix = substr($path, -1, 1) === '/' ? '/' : ''; $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); if ($path == null) { return false; } $internalPath = $this->getInternalPath($path . $postFix); $run = $this->runHooks($hooks, $path); if ($run and $storage = $this->getStorage($path . $postFix)) { if (!is_null($extraParam)) { $result = $storage->{$operation}($internalPath, $extraParam); } else { $result = $storage->{$operation}($internalPath); } $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) { if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open $this->runHooks($hooks, $path, true); } } return $result; } } return null; }