/**
  * 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]);
             }
         }
     }
 }
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\NotFound
  * @return \Sabre\DAV\INode
  */
 public function getNodeForPath($path)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $path = trim($path, '/');
     if (isset($this->cache[$path])) {
         return $this->cache[$path];
     }
     // Is it the root node?
     if (!strlen($path)) {
         return $this->rootNode;
     }
     if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
         // read from storage
         $absPath = $this->fileView->getAbsolutePath($path);
         $mount = $this->fileView->getMount($path);
         $storage = $mount->getStorage();
         $internalPath = $mount->getInternalPath($absPath);
         if ($storage) {
             /**
              * @var \OC\Files\Storage\Storage $storage
              */
             $scanner = $storage->getScanner($internalPath);
             // get data directly
             $data = $scanner->getData($internalPath);
             $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount);
         } else {
             $info = null;
         }
     } else {
         // read from cache
         try {
             $info = $this->fileView->getFileInfo($path);
         } catch (StorageNotAvailableException $e) {
             throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available');
         } catch (StorageInvalidException $e) {
             throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid');
         }
     }
     if (!$info) {
         throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
     }
     if ($info->getType() === 'dir') {
         $node = new \OC_Connector_Sabre_Directory($this->fileView, $info);
     } else {
         $node = new \OC_Connector_Sabre_File($this->fileView, $info);
     }
     $this->cache[$path] = $node;
     return $node;
 }
 public function renameHook($params)
 {
     $path1 = $params['oldpath'];
     $path2 = $params['newpath'];
     $fullPath1 = $this->baseView->getAbsolutePath($path1);
     $fullPath2 = $this->baseView->getAbsolutePath($path2);
     $mount1 = $this->baseView->getMount($path1);
     $mount2 = $this->baseView->getMount($path2);
     if ($mount1 instanceof SharedMount and $mount1->getInternalPath($fullPath1) !== '') {
         $this->propagateForOwner($mount1->getShare(), $mount1->getInternalPath($fullPath1), $mount1->getOwnerPropagator());
     }
     if ($mount1 !== $mount2 and $mount2 instanceof SharedMount and $mount2->getInternalPath($fullPath2) !== '') {
         $this->propagateForOwner($mount2->getShare(), $mount2->getInternalPath($fullPath2), $mount2->getOwnerPropagator());
     }
 }
Example #4
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);
 }
Example #5
0
 /**
  * reorganize folder structure for user
  *
  * @param string $user
  */
 public function reorganizeFolderStructureForUser($user)
 {
     // backup all keys
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($user);
     if ($this->backupUserKeys($user)) {
         // rename users private key
         $this->renameUsersPrivateKey($user);
         $this->renameUsersPublicKey($user);
         // rename file keys
         $path = '/files_encryption/keys';
         $this->renameFileKeys($user, $path);
         $trashPath = '/files_trashbin/keys';
         if (\OC_App::isEnabled('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) {
             $this->renameFileKeys($user, $trashPath, true);
             $this->view->deleteAll($trashPath);
         }
         // delete old folders
         $this->deleteOldKeys($user);
         $this->view->getMount('/' . $user)->getStorage()->getScanner()->scan('files_encryption');
     }
 }
Example #6
0
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @return \Sabre\DAV\INode
  * @throws InvalidPath
  * @throws \Sabre\DAV\Exception\Locked
  * @throws \Sabre\DAV\Exception\NotFound
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  */
 public function getNodeForPath($path)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $path = trim($path, '/');
     if (isset($this->cache[$path])) {
         return $this->cache[$path];
     }
     if ($path) {
         try {
             $this->fileView->verifyPath($path, basename($path));
         } catch (\OCP\Files\InvalidPathException $ex) {
             throw new InvalidPath($ex->getMessage());
         }
     }
     // Is it the root node?
     if (!strlen($path)) {
         return $this->rootNode;
     }
     if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
         // read from storage
         $absPath = $this->fileView->getAbsolutePath($path);
         $mount = $this->fileView->getMount($path);
         $storage = $mount->getStorage();
         $internalPath = $mount->getInternalPath($absPath);
         if ($storage && $storage->file_exists($internalPath)) {
             /**
              * @var \OC\Files\Storage\Storage $storage
              */
             // get data directly
             $data = $storage->getMetaData($internalPath);
             $info = new FileInfo($absPath, $storage, $internalPath, $data, $mount);
         } else {
             $info = null;
         }
     } else {
         // resolve chunk file name to real name, if applicable
         $path = $this->resolveChunkFile($path);
         // read from cache
         try {
             $info = $this->fileView->getFileInfo($path);
         } catch (StorageNotAvailableException $e) {
             throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available');
         } catch (StorageInvalidException $e) {
             throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid');
         } catch (LockedException $e) {
             throw new \Sabre\DAV\Exception\Locked();
         }
     }
     if (!$info) {
         throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
     }
     if ($info->getType() === 'dir') {
         $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this);
     } else {
         $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);
     }
     $this->cache[$path] = $node;
     return $node;
 }
Example #7
0
File: util.php Project: evanjt/core
 /**
  * get storage of path
  *
  * @param string $path
  * @return \OC\Files\Storage\Storage
  */
 public function getStorage($path)
 {
     $storage = $this->files->getMount($path)->getStorage();
     return $storage;
 }