/** * rename a file * * @param string $dir * @param string $oldname * @param string $newname * @return array */ public function rename($dir, $oldname, $newname) { $result = array('success' => false, 'data' => NULL); // rename to non-existing folder is denied if (!$this->view->file_exists($dir)) { $result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound'); // rename to existing file is denied } else { if ($this->view->file_exists($dir . '/' . $newname)) { $result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir))); } else { if ($newname !== '.' and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) { // successful rename $meta = $this->view->getFileInfo($dir . '/' . $newname); $fileinfo = \OCA\Files\Helper::formatFileInfo($meta); $result['success'] = true; $result['data'] = $fileinfo; } else { // rename failed $result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname))); } } } return $result; }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '') { if ($createFolder !== '') { $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder); } $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
protected function setUp() { parent::setUp(); //clear all proxies and hooks so we can do clean testing \OC_Hook::clear('OC_Filesystem'); //set up temporary storage $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $config = \OC::$server->getConfig(); $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); $config->setSystemValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \Test\Util\User\Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/test'); $this->instance = new \OC\Cache\File(); // forces creation of cache folder for subsequent tests $this->instance->set('hack', 'hack'); }
/** * Gets all versions of a note * * @NoAdminRequired * @NoCSRFRequired * @CORS * * @return array */ public function getAllVersions() { $source = $this->request->getParam("file_name", ""); list($uid, $filename) = Storage::getUidAndFilename($source); $versions = Storage::getVersions($uid, $filename, $source); $versionsResults = array(); if (is_array($versions) && count($versions) > 0) { require_once __DIR__ . '/../3rdparty/finediff/finediff.php'; $users_view = new View('/' . $uid); $currentData = $users_view->file_get_contents('files/' . $filename); // $previousData = $currentData; // $versions = array_reverse( $versions, true ); foreach ($versions as $versionData) { // get timestamp of version $mtime = (int) $versionData["version"]; // get filename of note version $versionFileName = 'files_versions/' . $filename . '.v' . $mtime; // load the data from the file $data = $users_view->file_get_contents($versionFileName); // calculate diff between versions $opcodes = \FineDiff::getDiffOpcodes($currentData, $data); $html = \FineDiff::renderDiffToHTMLFromOpcodes($currentData, $opcodes); $versionsResults[] = array("timestamp" => $mtime, "humanReadableTimestamp" => $versionData["humanReadableTimestamp"], "diffHtml" => $html, "data" => $data); // $previousData = $data; } // $versionsResults = array_reverse( $versionsResults ); } return array("file_name" => $source, "versions" => $versionsResults); }
/** * Get the template for a specific activity-event in the activities * * @param array $activity An array with all the activity data in it * @return string */ public function show($activity) { $tmpl = new Template('activity', 'stream.item'); $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp'])); $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp'])); if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) { // We do not link the subject as we create links for the parameters instead $activity['link'] = ''; } $tmpl->assign('event', $activity); if ($activity['file']) { $this->view->chroot('/' . $activity['affecteduser'] . '/files'); $exist = $this->view->file_exists($activity['file']); $is_dir = $this->view->is_dir($activity['file']); $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir)); // show a preview image if the file still exists $mimeType = Files::getMimeType($activity['file']); if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) { $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150))); } else { $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType); $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon; $tmpl->assign('previewImageLink', $mimeTypeIcon); $tmpl->assign('previewLinkIsDir', true); } } return $tmpl->fetchPage(); }
/** * @param string $userName * @return integer */ public function getMaximumStorageUsage($userName) { $view = new FilesView('/' . $userName . '/files'); $freeSpace = (int) $view->free_space(); $usedSpace = $view->getFileInfo('/')->getSize(); return $freeSpace + $usedSpace; }
/** * propagate the registered changes to their parent folders * * @param int $time (optional) the mtime to set for the folders, if not set the current time is used */ public function propagateChanges($time = null) { $changes = $this->getChanges(); $this->changedFiles = []; if (!$time) { $time = time(); } foreach ($changes as $change) { /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ $absolutePath = $this->view->getAbsolutePath($change); $mount = $this->view->getMount($change); $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($absolutePath); if ($storage) { $propagator = $storage->getPropagator(); $propagatedEntries = $propagator->propagateChange($internalPath, $time); foreach ($propagatedEntries as $entry) { $absolutePath = Filesystem::normalizePath($mount->getMountPoint() . '/' . $entry['path']); $relativePath = $this->view->getRelativePath($absolutePath); $this->emit('\\OC\\Files', 'propagate', [$relativePath, $entry]); } } } }
protected function setUp() { $app = new Application(); $this->container = $app->getContainer(); $this->container['Config'] = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->container['AppName'] = 'files_sharing'; $this->container['UserSession'] = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock(); $this->container['URLGenerator'] = $this->getMockBuilder('\\OC\\URLGenerator')->disableOriginalConstructor()->getMock(); $this->urlGenerator = $this->container['URLGenerator']; $this->shareController = $this->container['ShareController']; // Store current user $this->oldUser = \OC_User::getUser(); // Create a dummy user $this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER); \OC_User::createUser($this->user, $this->user); \OC_Util::tearDownFS(); \OC_User::setUserId(''); Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC_Util::setupFS($this->user); // Create a dummy shared file $view = new View('/' . $this->user . '/files'); $view->file_put_contents('file1.txt', 'I am such an awesome shared file!'); $this->token = \OCP\Share::shareItem(Filesystem::getFileInfo('file1.txt')->getType(), Filesystem::getFileInfo('file1.txt')->getId(), \OCP\Share::SHARE_TYPE_LINK, 'IAmPasswordProtected!', 1); }
/** * rename a file * * @param string $dir * @param string $oldname * @param string $newname * @return array */ public function rename($dir, $oldname, $newname) { $result = array('success' => false, 'data' => NULL); // rename to "/Shared" is denied if ($dir === '/' and $newname === 'Shared') { $result['data'] = array('message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved.")); // rename to existing file is denied } else { if ($this->view->file_exists($dir . '/' . $newname)) { $result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir))); } else { if ($newname !== '.' and !($dir === '/' and $oldname === 'Shared') and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) { // successful rename $meta = $this->view->getFileInfo($dir . '/' . $newname); if ($meta['mimetype'] === 'httpd/unix-directory') { $meta['type'] = 'dir'; } else { $meta['type'] = 'file'; } $fileinfo = array('id' => $meta['fileid'], 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'etag' => $meta['etag'], 'directory' => $dir, 'name' => $newname, 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']), 'icon' => \OCA\Files\Helper::determineIcon($meta)); $result['success'] = true; $result['data'] = $fileinfo; } else { // rename failed $result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname))); } } } return $result; }
/** * Get the template for a specific activity-event in the activities * * @param array $activity An array with all the activity data in it * @return string */ public static function show($activity) { $tmpl = new Template('activity', 'activity.box'); $tmpl->assign('formattedDate', Util::formatDate($activity['timestamp'])); $tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp'])); $tmpl->assign('user', $activity['user']); $tmpl->assign('displayName', User::getDisplayName($activity['user'])); if ($activity['app'] === 'files') { // We do not link the subject as we create links for the parameters instead $activity['link'] = ''; } $tmpl->assign('event', $activity); if ($activity['file']) { $rootView = new View('/' . $activity['affecteduser'] . '/files'); $exist = $rootView->file_exists($activity['file']); $is_dir = $rootView->is_dir($activity['file']); unset($rootView); // show a preview image if the file still exists $mimetype = \OC_Helper::getFileNameMimeType($activity['file']); if (!$is_dir && \OC::$server->getPreviewManager()->isMimeSupported($mimetype) && $exist) { $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file'])))); $tmpl->assign('previewImageLink', Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150))); } else { $tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => $activity['file']))); $tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon($is_dir ? 'dir' : $mimetype)); $tmpl->assign('previewLinkIsDir', true); } } return $tmpl->fetchPage(); }
static function folder($params) { $internalPath = $params['path']; $mountPoint = self::$mountPoints[$params['storage']]; $path = self::$view->getRelativePath($mountPoint . $internalPath); self::$eventSource->send('folder', $path); }
/** * @param string $path * @param int $maxX * @param int $maxY * @param boolean $scalingup * @param \OC\Files\View $fileview * @return bool|\OC_Image */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); //don't create previews of empty text files if (trim($content) === '') { return false; } $lines = preg_split("/\r\n|\n|\r/", $content); $fontSize = 5; //5px $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); imagecolorallocate($image, 255, 255, 255); $textColor = imagecolorallocate($image, 0, 0, 0); foreach ($lines as $index => $line) { $index = $index + 1; $x = (int) 1; $y = (int) ($index * $lineSize) - $fontSize; imagestring($image, 1, $x, $y, $line, $textColor); if ($index * $lineSize >= $maxY) { break; } } $image = new \OC_Image($image); return $image->valid() ? $image : false; }
/** * @dataProvider prepareParametersData */ public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '', $enableAvatars = true) { if ($createFolder !== '') { $this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder); } $this->config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn($enableAvatars); $this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams)); }
/** * @param string $userName * @return integer */ public function byUsername($userName) { $view = new FilesView('/' . $userName . '/files'); $freeSpace = (int) $view->free_space(); $fileInfo = $view->getFileInfo('/'); Assertion::notEmpty($fileInfo); $usedSpace = $fileInfo->getSize(); return KiloBytes::allocateUnits($freeSpace + $usedSpace)->units(); }
/** * @param $parentUri * @return mixed */ public function getFreeSpace($parentUri) { if (is_null($this->fileView)) { // initialize fileView $this->fileView = \OC\Files\Filesystem::getView(); } $freeSpace = $this->fileView->free_space($parentUri); return $freeSpace; }
public function testChangeLock() { Filesystem::initMountPoints($this->recipientUid); $recipientView = new View('/' . $this->recipientUid . '/files'); $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED); $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue(true); }
/** * Check if genesis is valid * @param \OC\Files\View $view * @param string $path relative to the view * @throws \Exception */ protected function validate($view, $path) { if (!$view->file_exists($path)) { throw new \Exception('Document not found ' . $path); } if (!$view->is_file($path)) { throw new \Exception('Object ' . $path . ' is not a file.'); } //TODO check if it is a valid odt }
/** * @brief retrieve the ENCRYPTED private key from a user * * @param \OC\Files\View $view * @param string $user * @return string private key or false (hopefully) * @note the key returned by this method must be decrypted before use */ public static function getPrivateKey($view, $user) { $path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key'; $key = false; $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; if ($view->file_exists($path)) { $key = $view->file_get_contents($path); } \OC_FileProxy::$enabled = $proxyStatus; return $key; }
/** * @param array $share * @param string $internalPath * @param \OC\Files\Cache\ChangePropagator $propagator */ private function propagateForOwner($share, $internalPath, ChangePropagator $propagator) { // note that we have already set up the filesystem for the owner when mounting the share $view = new View('/' . $share['uid_owner'] . '/files'); $shareRootPath = $view->getPath($share['item_source']); if (!is_null($shareRootPath)) { $path = $shareRootPath . '/' . $internalPath; $path = Filesystem::normalizePath($path); $propagator->addChange($path); $propagator->propagateChanges(); } }
public function run() { $view = new View('/'); $children = $view->getDirectoryContent('/'); foreach ($children as $child) { if ($view->is_dir($child->getPath())) { $thumbnailsFolder = $child->getPath() . '/thumbnails'; if ($view->is_dir($thumbnailsFolder)) { $view->rmdir($thumbnailsFolder); } } } }
/** * @param string[] $users * @param string $subPath */ protected function assertEtagsNotChanged($users, $subPath = '') { $oldUser = \OC::$server->getUserSession()->getUser(); foreach ($users as $user) { $this->loginAsUser($user); $id = $this->fileIds[$user][$subPath]; $path = $this->rootView->getPath($id); $etag = $this->rootView->getFileInfo($path)->getEtag(); $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed'); $this->fileEtags[$id] = $etag; } $this->loginAsUser($oldUser->getUID()); }
public function testUpdatedFile() { $this->view->file_put_contents('/foo.txt', 'bar'); $cached = $this->cache->get('foo.txt'); $this->assertEquals(3, $cached['size']); $this->assertEquals('text/plain', $cached['mimetype']); $this->storage->file_put_contents('foo.txt', 'qwerty'); $cached = $this->cache->get('foo.txt'); $this->assertEquals(3, $cached['size']); $this->updater->update('/foo.txt'); $cached = $this->cache->get('foo.txt'); $this->assertEquals(6, $cached['size']); }
/** * @return Directory */ private function impl() { $rootView = new View(); $user = \OC::$server->getUserSession()->getUser(); Filesystem::initMountPoints($user->getUID()); if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { $rootView->mkdir('/' . $user->getUID() . '/uploads'); } $view = new View('/' . $user->getUID() . '/uploads'); $rootInfo = $view->getFileInfo(''); $impl = new Directory($view, $rootInfo); return $impl; }
/** * @param \OCP\Files\FileInfo $dir * @param \OC\Files\View $view * @return array */ function getChildInfo($dir, $view) { $children = $view->getDirectoryContent($dir->getPath()); $result = array(); foreach ($children as $child) { $formated = \OCA\Files\Helper::formatFileInfo($child); if ($child->getType() === 'dir') { $formated['children'] = getChildInfo($child, $view); } $formated['mtime'] = $formated['mtime'] / 1000; $result[] = $formated; } return $result; }
/** * check if the parent folder exists otherwise move the mount point up * * @param array $share * @return string */ private function verifyMountPoint(&$share) { $mountPoint = basename($share['file_target']); $parent = dirname($share['file_target']); if (!$this->recipientView->is_dir($parent)) { $parent = Helper::getShareFolder(); } $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), [], $this->recipientView); if ($newMountPoint !== $share['file_target']) { $this->updateFileTarget($newMountPoint, $share); $share['file_target'] = $newMountPoint; $share['unique_name'] = true; } return $newMountPoint; }
/** * @param string $user * @return \OC\Files\Cache\ChangePropagator */ public function getChangePropagator($user) { $activeUser = $this->userSession->getUser(); // for the local user we want to propagator from the active view, not any cached one if ($activeUser && $activeUser->getUID() === $user && Filesystem::getView() instanceof View) { // it's important that we take the existing propagator here to make sure we can listen to external changes $this->changePropagators[$user] = Filesystem::getView()->getUpdater()->getPropagator(); } if (isset($this->changePropagators[$user])) { return $this->changePropagators[$user]; } $view = new View('/' . $user . '/files'); $this->changePropagators[$user] = $view->getUpdater()->getPropagator(); return $this->changePropagators[$user]; }
/** * Prepares a file parameter for usage * * Removes the path from filenames and adds highlights * * @param string $param * @param bool $stripPath Shall we remove the path from the filename * @param bool $highlightParams * @return string */ protected function prepareFileParam($param, $stripPath, $highlightParams) { $param = $this->fixLegacyFilename($param); $is_dir = $this->rootView->is_dir('/' . User::getUser() . '/files' . $param); if ($is_dir) { $fileLink = Util::linkTo('files', 'index.php', array('dir' => $param)); } else { $parentDir = substr_count($param, '/') == 1 ? '/' : dirname($param); $fileName = basename($param); $fileLink = Util::linkTo('files', 'index.php', array('dir' => $parentDir, 'scrollto' => $fileName)); } $param = trim($param, '/'); list($path, $name) = $this->splitPathFromFilename($param); if (!$stripPath || $path === '') { if (!$highlightParams) { return $param; } return '<a class="filename" href="' . $fileLink . '">' . Util::sanitizeHTML($param) . '</a>'; } if (!$highlightParams) { return $name; } $title = ' title="' . $this->l->t('in %s', array(Util::sanitizeHTML($path))) . '"'; return '<a class="filename tooltip" href="' . $fileLink . '"' . $title . '>' . Util::sanitizeHTML($name) . '</a>'; }
protected function verifyNewKeyPath($uid) { // private key if ($uid !== '') { $this->assertTrue($this->view->file_exists($uid . '/files_encryption/' . $this->moduleId . '/' . $uid . '.privateKey')); } // file keys $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/folder3/file3/' . $this->moduleId . '/fileKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/file2/' . $this->moduleId . '/fileKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/file.1/' . $this->moduleId . '/fileKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/fileKey')); // share keys $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/folder3/file3/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/folder3/file3/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/folder3/file3/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/file2/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/file2/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/folder2/file2/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/file.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/file.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder1/file.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); if ($this->public_share_key_id) { $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/' . $this->public_share_key_id . '.shareKey')); } if ($this->recovery_key_id) { $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/files/folder2/file.2.1/' . $this->moduleId . '/' . $this->recovery_key_id . '.shareKey')); } }
/** * 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); }
/** * Test restoring a file into a read-only folder, will restore * the file to root instead */ public function testRestoreFileIntoReadOnlySourceFolder() { $userFolder = \OC::$server->getUserFolder(); $folder = $userFolder->newFolder('folder'); $file = $folder->newFile('file1.txt'); $file->putContent('foo'); $this->assertTrue($userFolder->nodeExists('folder/file1.txt')); $file->delete(); $this->assertFalse($userFolder->nodeExists('folder/file1.txt')); $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime'); $this->assertCount(1, $filesInTrash); /** @var \OCP\Files\FileInfo */ $trashedFile = $filesInTrash[0]; // delete source folder list($storage, $internalPath) = $this->rootView->resolvePath('/' . self::TEST_TRASHBIN_USER1 . '/files/folder'); if ($storage instanceof \OC\Files\Storage\Local) { $folderAbsPath = $storage->getSourcePath($internalPath); // make folder read-only chmod($folderAbsPath, 0555); $this->assertTrue(OCA\Files_Trashbin\Trashbin::restore('file1.txt.d' . $trashedFile->getMtime(), $trashedFile->getName(), $trashedFile->getMtime())); $file = $userFolder->get('file1.txt'); $this->assertEquals('foo', $file->getContent()); chmod($folderAbsPath, 0755); } }