Пример #1
0
 /**
  * @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());
 }
Пример #2
0
 public function isLocal()
 {
     $this->init();
     $ownerPath = $this->ownerView->getPath($this->share['item_source']);
     list($targetStorage) = $this->ownerView->resolvePath($ownerPath);
     return $targetStorage->isLocal();
 }
Пример #3
0
 /**
  * Add notifications for the owners whose files have been reshared
  *
  * @param string $currentOwner
  * @param string $subject
  * @param string $shareWith
  * @param int $fileSource
  * @param string $itemType
  */
 protected function shareNotificationForOriginalOwners($currentOwner, $subject, $shareWith, $fileSource, $itemType)
 {
     // Get the full path of the current user
     $this->view->chroot('/' . $currentOwner . '/files');
     try {
         $path = $this->view->getPath($fileSource);
     } catch (NotFoundException $e) {
         return;
     }
     /**
      * Get the original owner and his path
      */
     $owner = $this->view->getOwner($path);
     if ($owner !== $currentOwner) {
         $this->reshareNotificationForSharer($owner, $subject, $shareWith, $fileSource, $itemType);
     }
     /**
      * Get the sharee who shared the item with the currentUser
      */
     $this->view->chroot('/' . $currentOwner . '/files');
     $mount = $this->view->getMount($path);
     if (!$mount instanceof IMountPoint) {
         return;
     }
     $storage = $mount->getStorage();
     if (!$storage->instanceOfStorage('OC\\Files\\Storage\\Shared')) {
         return;
     }
     /** @var \OC\Files\Storage\Shared $storage */
     $shareOwner = $storage->getSharedFrom();
     if ($shareOwner === '' || $shareOwner === null || $shareOwner === $owner || $shareOwner === $currentOwner) {
         return;
     }
     $this->reshareNotificationForSharer($shareOwner, $subject, $shareWith, $fileSource, $itemType);
 }
Пример #4
0
 /**
  * @param string $user
  * @param int $fileId
  * @param string $filePath
  * @return array
  */
 protected function findInfoById($user, $fileId, $filePath)
 {
     $this->view->chroot('/' . $user . '/files');
     $cache = ['path' => $filePath, 'exists' => false, 'is_dir' => false, 'view' => ''];
     $notFound = false;
     try {
         $path = $this->view->getPath($fileId);
         $cache['path'] = $path;
         $cache['is_dir'] = $this->view->is_dir($path);
         $cache['exists'] = true;
     } catch (NotFoundException $e) {
         // The file was not found in the normal view, maybe it is in
         // the trashbin?
         $this->view->chroot('/' . $user . '/files_trashbin');
         try {
             $path = $this->view->getPath($fileId);
             $cache = ['path' => substr($path, strlen('/files')), 'exists' => true, 'is_dir' => $this->view->is_dir($path), 'view' => 'trashbin'];
         } catch (NotFoundException $e) {
             $notFound = true;
         }
     }
     $this->cacheId[$user][$fileId] = $cache;
     if ($notFound) {
         $this->cacheId[$user][$fileId]['path'] = null;
     }
     return $cache;
 }
Пример #5
0
 public static function getUidAndFilename($filename)
 {
     $uid = \OC\Files\Filesystem::getOwner($filename);
     \OC\Files\Filesystem::initMountPoints($uid);
     if ($uid != \OCP\User::getUser()) {
         $info = \OC\Files\Filesystem::getFileInfo($filename);
         $ownerView = new \OC\Files\View('/' . $uid . '/files');
         $filename = $ownerView->getPath($info['fileid']);
     }
     return array($uid, $filename);
 }
Пример #6
0
 /**
  * @param string $path
  * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
  * @param \OCP\Lock\ILockingProvider $provider
  */
 public function releaseLock($path, $type, ILockingProvider $provider)
 {
     /** @var \OCP\Files\Storage $targetStorage */
     list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
     $targetStorage->releaseLock($targetInternalPath, $type, $provider);
     // unlock the parent folders of the owner when unlocking the share as recipient
     if ($path === '') {
         $sourcePath = $this->ownerView->getPath($this->share['file_source']);
         $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
     }
 }
Пример #7
0
 /**
  * @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();
     }
 }
Пример #8
0
 /**
  * @param string $filename
  * @return array
  * @throws \OC\User\NoUserException
  */
 public static function getUidAndFilename($filename)
 {
     $uid = \OC\Files\Filesystem::getOwner($filename);
     \OC\Files\Filesystem::initMountPoints($uid);
     if ($uid != \OCP\User::getUser()) {
         $info = \OC\Files\Filesystem::getFileInfo($filename);
         $ownerView = new \OC\Files\View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
         } catch (NotFoundException $e) {
             $filename = null;
         }
     }
     return [$uid, $filename];
 }
Пример #9
0
 /**
  * update keyfiles and share keys recursively
  *
  * @param int $fileSource file source id
  */
 private function update($fileSource)
 {
     $path = \OC\Files\Filesystem::getPath($fileSource);
     $info = \OC\Files\Filesystem::getFileInfo($path);
     $owner = \OC\Files\Filesystem::getOwner($path);
     $view = new \OC\Files\View('/' . $owner . '/files');
     $ownerPath = $view->getPath($info->getId());
     $absPath = '/' . $owner . '/files' . $ownerPath;
     $mount = $this->mountManager->find($path);
     $mountPoint = $mount->getMountPoint();
     // if a folder was shared, get a list of all (sub-)folders
     if ($this->view->is_dir($absPath)) {
         $allFiles = $this->util->getAllFiles($absPath, $mountPoint);
     } else {
         $allFiles = array($absPath);
     }
     $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
     foreach ($allFiles as $path) {
         $usersSharing = $this->file->getAccessList($path);
         $encryptionModule->update($path, $this->uid, $usersSharing);
     }
 }
Пример #10
0
 /**
  * @param string $owner
  * @param int $fileId
  * @param string $filePath
  * @return array
  */
 protected function getPreview($owner, $fileId, $filePath)
 {
     $this->view->chroot('/' . $owner . '/files');
     $path = $this->view->getPath($fileId);
     if ($path === null || $path === '' || !$this->view->file_exists($path)) {
         return $this->getPreviewFromPath($filePath);
     }
     $is_dir = $this->view->is_dir($path);
     $preview = ['link' => $this->getPreviewLink($path, $is_dir), 'source' => '', 'isMimeTypeIcon' => true];
     // show a preview image if the file still exists
     if ($is_dir) {
         $preview['source'] = $this->getPreviewPathFromMimeType('dir');
     } else {
         $fileInfo = $this->view->getFileInfo($path);
         if ($this->preview->isAvailable($fileInfo)) {
             $preview['isMimeTypeIcon'] = false;
             $preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $path, 'c' => $this->view->getETag($path), 'x' => 150, 'y' => 150]);
         } else {
             $preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype());
         }
     }
     return $preview;
 }
Пример #11
0
 /**
  * @param string $filename
  * @return array
  * @throws \OC\User\NoUserException
  * @throws NotFoundException
  */
 public function getUidAndFilename($filename)
 {
     $info = $this->getFileInfo($filename);
     if (!$info instanceof \OCP\Files\FileInfo) {
         throw new NotFoundException($this->getAbsolutePath($filename) . ' not found');
     }
     $uid = $info->getOwner()->getUID();
     if ($uid != \OCP\User::getUser()) {
         Filesystem::initMountPoints($uid);
         $ownerView = new View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
         } catch (NotFoundException $e) {
             throw new NotFoundException('File with id ' . $info['fileid'] . ' not found for user ' . $uid);
         }
     }
     return [$uid, $filename];
 }
Пример #12
0
 public function propagateById($id)
 {
     if (isset($this->propagatingIds[$id])) {
         return;
     }
     $this->propagatingIds[$id] = true;
     $shares = Share::getAllSharesForFileId($id);
     foreach ($shares as $share) {
         // propagate down the share tree
         $this->markDirty($share, microtime(true));
         // propagate up the share tree
         if ($this->isRecipientOfShare($share)) {
             $user = $share['uid_owner'];
             $view = new View('/' . $user . '/files');
             $path = $view->getPath($share['file_source']);
             $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user));
             $watcher->writeHook(['path' => $path]);
         }
     }
     unset($this->propagatingIds[$id]);
 }
Пример #13
0
 /**
  * Get the path of a file by id
  *
  * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file
  *
  * @param int $id
  * @throws NotFoundException
  * @return string
  */
 public static function getPath($id)
 {
     return self::$defaultInstance->getPath($id);
 }
Пример #14
0
 /**
  * 
  * @return string owner of the current file item
  * @throws \Exception
  */
 public function getOwnerViewAndPath($useDefaultRoot = false)
 {
     if ($this->isPublicShare()) {
         if (isset($this->sharing['uid_owner'])) {
             $owner = $this->sharing['uid_owner'];
             if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) {
                 throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist ');
             }
             \OC_Util::tearDownFS();
             \OC_Util::setupFS($this->sharing['uid_owner']);
         } else {
             throw new \Exception($this->fileId . ' is a broken share');
         }
         $view = new View('/' . $owner . '/files');
     } else {
         $owner = \OC::$server->getUserSession()->getUser()->getUID();
         $root = '/' . $owner;
         if ($useDefaultRoot) {
             $root .= '/' . 'files';
         }
         $view = new View($root);
     }
     $path = $view->getPath($this->fileId);
     if (!$path) {
         throw new \Exception($this->fileId . ' can not be resolved');
     }
     $this->path = $path;
     $this->owner = $owner;
     if (!$view->file_exists($this->path)) {
         throw new \Exception($this->path . ' doesn\'t exist');
     }
     return array($view, $this->path);
 }
Пример #15
0
 /**
  * get owner and path relative to data/<owner>/files
  *
  * @param string $path path to file for current user
  * @return array ['owner' => $owner, 'path' => $path]
  * @throw \InvalidArgumentException
  */
 protected function getOwnerPath($path)
 {
     $info = Filesystem::getFileInfo($path);
     $owner = Filesystem::getOwner($path);
     $view = new View('/' . $owner . '/files');
     $path = $view->getPath($info->getId());
     if ($path === null) {
         throw new \InvalidArgumentException('No file found for ' . $info->getId());
     }
     return array($owner, $path);
 }
Пример #16
0
 protected function idtoDom($id)
 {
     $id = (int) $id;
     $view = new \OC\Files\View('');
     //! need root ?
     $path = $view->getPath($id);
     $DOM = new GpxDOM();
     $DOM->loadXML($view->file_get_contents($path));
     return $DOM;
 }
Пример #17
0
 /**
  * Return the source
  *
  * @param string $path
  * @return array
  */
 protected function getSourcePathAndOwner($path)
 {
     $uidOwner = Filesystem::getOwner($path);
     if ($uidOwner !== $this->currentUser) {
         Filesystem::initMountPoints($uidOwner);
         $info = Filesystem::getFileInfo($path);
         if ($info !== false) {
             $ownerView = new View('/' . $uidOwner . '/files');
             $path = $ownerView->getPath((int) $info['fileid']);
         }
     }
     return array($path, $uidOwner);
 }
Пример #18
0
 public function propagateById($id)
 {
     $shares = Share::getAllSharesForFileId($id);
     foreach ($shares as $share) {
         // propagate down the share tree
         $this->markDirty($share, microtime(true));
         // propagate up the share tree
         if ($share['share_with'] === $this->userId) {
             $user = $share['uid_owner'];
             $view = new View('/' . $user . '/files');
             $path = $view->getPath($share['file_source']);
             $watcher = new ChangeWatcher($view, $this->manager->getSharePropagator($user));
             $watcher->writeHook(['path' => $path]);
         }
     }
 }
Пример #19
0
 private function resolveOwnerPath($path, $info)
 {
     if (!$this->isShared($path)) {
         return array(null, null, null);
     }
     if (isset($info['fileid'])) {
         $fileId = $info['fileid'];
         $owner = $this->view->getOwner($path);
         $ownerView = new View("/{$owner}/files");
         $path = $ownerView->getPath($fileId);
         return array($owner, $path, $info);
     }
     return array(null, null, null);
 }
Пример #20
0
 /**
  * get the UID of the owner of the file and the path to the file relative to
  * owners files folder
  *
  * @param $filename
  * @return array
  * @throws \OC\User\NoUserException
  */
 public static function getUidAndFilename($filename)
 {
     $uid = Filesystem::getOwner($filename);
     $userManager = \OC::$server->getUserManager();
     // if the user with the UID doesn't exists, e.g. because the UID points
     // to a remote user with a federated cloud ID we use the current logged-in
     // user. We need a valid local user to create the share
     if (!$userManager->userExists($uid)) {
         $uid = User::getUser();
     }
     Filesystem::initMountPoints($uid);
     if ($uid != User::getUser()) {
         $info = Filesystem::getFileInfo($filename);
         $ownerView = new View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
         } catch (NotFoundException $e) {
             $filename = null;
         }
     }
     return [$uid, $filename];
 }
 /**
  * Listen on the propagator for updates made to shares owned by a user
  *
  * @param \OC\Files\Cache\ChangePropagator $propagator
  * @param string $owner
  */
 public function attachToPropagator(ChangePropagator $propagator, $owner)
 {
     $propagator->listen('\\OC\\Files', 'propagate', function ($path, $entry) use($owner) {
         $shares = Share::getAllSharesForFileId($entry['fileid']);
         foreach ($shares as $share) {
             // propagate down the share tree
             $this->markDirty($share, microtime(true));
             // propagate up the share tree
             $user = $share['uid_owner'];
             $view = new View('/' . $user . '/files');
             $path = $view->getPath($share['file_source']);
             $watcher = new ChangeWatcher($view);
             $watcher->writeHook(['path' => $path]);
         }
     });
 }