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; } } }
/** * update the filesystem after a rename has been detected * @param string oldPath * @param string newPath * @param string root (optional) */ public static function rename($oldPath, $newPath, $root = false) { if (!OC_FileCache::inCache($oldPath, $root)) { return; } if ($root === false) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root); } $cached = OC_FileCache_Cached::get($oldPath, $root); $oldSize = $cached['size']; OC_FileCache::increaseSize(dirname($oldPath), -$oldSize, $root); OC_FileCache::increaseSize(dirname($newPath), $oldSize, $root); OC_FileCache::move($oldPath, $newPath); }
/** * delete non existing files from the cache */ private static function cleanFolder($path, $root = '') { if (!$root) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root == '/' ? '' : $root); } //check for removed files, not using getFolderContent to prevent loops $parent = self::getFileId($view->getRoot() . $path); $query = OC_DB::prepare('SELECT name FROM *PREFIX*fscache WHERE parent=?'); $result = $query->execute(array($parent)); while ($row = $result->fetchRow()) { $file = $path . '/' . $row['name']; if (!$view->file_exists($file)) { if (!$root) { //filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem', 'post_delete', array('path' => $file)); } else { self::fileSystemWatcherDelete(array('path' => $file), $root); } } } }
/** * scan a single file * @param string path * @param string root (optional) * @return int size of the scanned file */ public static function scanFile($path, $root = false) { // NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache) if (substr($path, 0, 7) == '/Shared') { return; } if ($root === false) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root); } if (!$view->is_readable($path)) { return; } //cant read, nothing we can do clearstatcache(); $mimetype = $view->getMimeType($path); $stat = $view->stat($path); if ($mimetype == 'httpd/unix-directory') { $stat['size'] = 0; $writable = $view->is_writable($path . '/'); } else { $writable = $view->is_writable($path); } $stat['mimetype'] = $mimetype; $stat['writable'] = $writable; if ($path == '/') { $path = ''; } self::put($path, $stat, $root); return $stat['size']; }
public function testHooks() { if (OC_Filesystem::getView()) { $user = OC_User::getUser(); } else { $user = uniqid(); OC_Filesystem::init('/' . $user . '/files'); } OC_Hook::clear('OC_Filesystem'); OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/'); $rootView = new OC_FilesystemView(''); $rootView->mkdir('/' . $user); $rootView->mkdir('/' . $user . '/files'); OC_Filesystem::file_put_contents('/foo', 'foo'); OC_Filesystem::mkdir('/bar'); OC_Filesystem::file_put_contents('/bar//foo', 'foo'); $tmpFile = OC_Helper::tmpFile(); file_put_contents($tmpFile, 'foo'); $fh = fopen($tmpFile, 'r'); OC_Filesystem::file_put_contents('/bar//foo', $fh); }