/** * Copies a file or directory. * * This method must work recursively and delete the destination * if it exists * * @param string $source * @param string $destination * @throws \Sabre\DAV\Exception\ServiceUnavailable * @return void */ public function copy($source, $destination) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } // this will trigger existence check $this->getNodeForPath($source); list($destinationDir, $destinationName) = \Sabre\HTTP\URLUtil::splitPath($destination); try { $this->fileView->verifyPath($destinationDir, $destinationName); } catch (\OCP\Files\InvalidPathException $ex) { throw new InvalidPath($ex->getMessage()); } try { $this->fileView->copy($source, $destination); } catch (StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } catch (ForbiddenException $ex) { throw new Forbidden($ex->getMessage(), $ex->getRetry()); } catch (LockedException $e) { throw new FileLocked($e->getMessage(), $e->getCode(), $e); } list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destination); $this->markDirty($destinationDir); }
/** * Copies a file or directory. * * This method must work recursively and delete the destination * if it exists * * @param string $source * @param string $destination * @throws \Sabre\DAV\Exception\ServiceUnavailable * @return void */ public function copy($source, $destination) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } try { if ($this->fileView->is_file($source)) { $this->fileView->copy($source, $destination); } else { $this->fileView->mkdir($destination); $dh = $this->fileView->opendir($source); if (is_resource($dh)) { while (($subNode = readdir($dh)) !== false) { if ($subNode == '.' || $subNode == '..') { continue; } $this->copy($source . '/' . $subNode, $destination . '/' . $subNode); } } } } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destination); $this->markDirty($destinationDir); }
/** * create backup of user specific keys * * @param string $user * @return bool */ private function backupUserKeys($user) { $encryptionDir = $user . '/files_encryption'; if ($this->view->is_dir($encryptionDir)) { $backupDir = $user . '/encryption_migration_backup_' . date("Y-m-d_H-i-s"); $this->view->mkdir($backupDir); $this->view->copy($encryptionDir, $backupDir); return true; } return false; }
/** * copy keys if a file was renamed * * @param string $source * @param string $target * @return boolean */ public function copyKeys($source, $target) { $sourcePath = $this->getPathToKeys($source); $targetPath = $this->getPathToKeys($target); if ($this->view->file_exists($sourcePath)) { $this->keySetPreparation(dirname($targetPath)); $this->view->copy($sourcePath, $targetPath); return true; } return false; }
/** * create a backup of all keys from the user * * @param string $purpose define the purpose of the backup, will be part of the backup folder name * @param boolean $timestamp (optional) should a timestamp be added, default true * @param boolean $includeUserKeys (optional) include users private-/public-key, default true */ public function backupAllKeys($purpose, $timestamp = true, $includeUserKeys = true) { $this->userId; $backupDir = $this->encryptionDir . '/backup.' . $purpose; $backupDir .= $timestamp ? '.' . date("Y-m-d_H-i-s") . '/' : '/'; $this->view->mkdir($backupDir); $this->view->copy($this->keysPath, $backupDir . 'keys/'); if ($includeUserKeys) { $this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.privateKey'); $this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.publicKey'); } }
/** * encrypt file * * @param string $path * @return bool */ protected function encryptFile($path) { $source = $path; $target = $path . '.encrypted.' . time(); try { $this->rootView->copy($source, $target); $this->rootView->rename($target, $source); } catch (DecryptionFailedException $e) { if ($this->rootView->file_exists($target)) { $this->rootView->unlink($target); } return false; } return true; }
/** * Copies a file or directory. * * This method must work recursively and delete the destination * if it exists * * @param string $source * @param string $destination * @throws \Sabre\DAV\Exception\ServiceUnavailable * @return void */ public function copy($source, $destination) { if (!$this->fileView) { throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup'); } // this will trigger existence check $this->getNodeForPath($source); try { $this->fileView->copy($source, $destination); } catch (\OCP\Files\StorageNotAvailableException $e) { throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage()); } list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destination); $this->markDirty($destinationDir); }
/** * copy keys if a file was renamed * * @param string $source * @param string $target * @param string $owner * @param bool $systemWide */ public function copyKeys($source, $target) { list($owner, $source) = $this->util->getUidAndFilename($source); list(, $target) = $this->util->getUidAndFilename($target); $systemWide = $this->util->isSystemWideMountPoint($target); if ($systemWide) { $sourcePath = $this->keys_base_dir . $source . '/'; $targetPath = $this->keys_base_dir . $target . '/'; } else { $sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/'; $targetPath = '/' . $owner . $this->keys_base_dir . $target . '/'; } if ($this->view->file_exists($sourcePath)) { $this->keySetPreparation(dirname($targetPath)); $this->view->copy($sourcePath, $targetPath); } }
private function renameShareKeys($user, $filePath, $filename, $target, $trash) { $oldShareKeyPath = $this->getOldShareKeyPath($user, $filePath, $trash); $dh = $this->view->opendir($oldShareKeyPath); if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { if (!\OC\Files\Filesystem::isIgnoredDir($file)) { if ($this->view->is_dir($oldShareKeyPath . '/' . $file)) { continue; } else { if (substr($file, 0, strlen($filename) + 1) === $filename . '.') { $uid = $this->getUidFromShareKey($file, $filename, $trash); $this->view->copy($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey'); } } } } closedir($dh); } }
/** * Rollback to an old version of a file. * * @param string $file file name * @param int $revision revision timestamp */ public static function rollback($file, $revision) { if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') { // add expected leading slash $file = '/' . ltrim($file, '/'); list($uid, $filename) = self::getUidAndFilename($file); $users_view = new View('/' . $uid); $files_view = new View('/' . User::getUser() . '/files'); $versionCreated = false; //first create a new version $version = 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename); if (!$users_view->file_exists($version)) { $users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . $users_view->filemtime('files' . $filename)); $versionCreated = true; } $fileToRestore = 'files_versions' . $filename . '.v' . $revision; // Restore encrypted version of the old file for the newly restored file // This has to happen manually here since the file is manually copied below $oldVersion = $users_view->getFileInfo($fileToRestore)->getEncryptedVersion(); $newFileInfo = $files_view->getFileInfo($filename); $cache = $newFileInfo->getStorage()->getCache(); $cache->update($newFileInfo->getId(), ['encrypted' => $oldVersion, 'encryptedVersion' => $oldVersion]); // rollback if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) { $files_view->touch($file, $revision); Storage::scheduleExpire($uid, $file); \OC_Hook::emit('\\OCP\\Versions', 'rollback', array('path' => $filename, 'revision' => $revision)); return true; } else { if ($versionCreated) { self::deleteVersion($users_view, $version); } } } return false; }
public static function copy($path1, $path2) { return self::$defaultInstance->copy($path1, $path2); }