public function copy($path1, $path2) { $postFix1 = substr($path1, -1, 1) === '/' ? '/' : ''; $postFix2 = substr($path2, -1, 1) === '/' ? '/' : ''; $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); if (OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); if ($path1 == null or $path2 == null) { return false; } $run = true; if ($this->fakeRoot == OC_Filesystem::getRoot()) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2, OC_Filesystem::signal_param_run => &$run)); $exists = $this->file_exists($path2); if ($run and !$exists) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); } if ($run) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); } } if ($run) { $mp1 = $this->getMountPoint($path1 . $postFix1); $mp2 = $this->getMountPoint($path2 . $postFix2); if ($mp1 == $mp2) { if ($storage = $this->getStorage($path1 . $postFix1)) { $result = $storage->copy($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2)); } } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } if ($this->fakeRoot == OC_Filesystem::getRoot()) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2)); if (!$exists) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path2)); } OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path2)); } else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions OC_FileCache_Update::update($path2, $this->fakeRoot); OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot); } return $result; } } }
/** * recursively scan the filesystem and fill the cache * @param string $path * @param OC_EventSource $enventSource (optional) * @param int count (optional) * @param string root (optional) */ public static function scan($path, $eventSource = false, &$count = 0, $root = false) { if ($eventSource) { $eventSource->send('scanning', array('file' => $path, 'count' => $count)); } $lastSend = $count; // 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); } self::scanFile($path, $root); $dh = $view->opendir($path . '/'); $totalSize = 0; if ($dh) { while (($filename = readdir($dh)) !== false) { if ($filename != '.' and $filename != '..') { $file = $path . '/' . $filename; if ($view->is_dir($file . '/')) { self::scan($file, $eventSource, $count, $root); } else { $totalSize += self::scanFile($file, $root); $count++; if ($count > $lastSend + 25 and $eventSource) { $lastSend = $count; $eventSource->send('scanning', array('file' => $path, 'count' => $count)); } } } } } OC_FileCache_Update::cleanFolder($path, $root); self::increaseSize($path, $totalSize, $root); }
public function copy($path1, $path2) { $postFix1 = substr($path1, -1, 1) === '/' ? '/' : ''; $postFix2 = substr($path2, -1, 1) === '/' ? '/' : ''; $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); if (OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); if ($path1 == null or $path2 == null) { return false; } $run = true; if ($this->fakeRoot == OC_Filesystem::getRoot()) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2, OC_Filesystem::signal_param_run => &$run)); $exists = $this->file_exists($path2); if ($run and !$exists) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); } if ($run) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); } } if ($run) { $mp1 = $this->getMountPoint($path1 . $postFix1); $mp2 = $this->getMountPoint($path2 . $postFix2); if ($mp1 == $mp2) { if ($storage = $this->getStorage($path1 . $postFix1)) { $result = $storage->copy($this->getInternalPath($path1 . $postFix1), $this->getInternalPath($path2 . $postFix2)); } } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } if ($this->fakeRoot == OC_Filesystem::getRoot()) { // If the file to be copied originates within // the user's data directory OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array(OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath => $path2)); if (!$exists) { OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path2)); } OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path2)); } else { // If this is not a normal file copy operation // and the file originates somewhere else // (e.g. a version rollback operation), do not // perform all the other post_write actions // Update webdav properties OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot); $splitPath2 = explode('/', $path2); // Only cache information about files // that are being copied from within // the user files directory. Caching // other files, like VCS backup files, // serves no purpose if ($splitPath2[1] == 'files') { OC_FileCache_Update::update($path2, $this->fakeRoot); } } return $result; } } }