コード例 #1
0
ファイル: manager.php プロジェクト: evanjt/core
 public function testLong()
 {
     $storage = new LongId(array());
     $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
     $this->manager->addMount($mount);
     $id = $mount->getStorageId();
     $storageId = $storage->getId();
     $this->assertEquals(array($mount), $this->manager->findByStorageId($id));
     $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId));
     $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId)));
 }
コード例 #2
0
ファイル: Filesystem.php プロジェクト: stweil/owncloud-core
 /**
  * @param string $id
  * @return Mount\MountPoint[]
  */
 public static function getMountByStorageId($id)
 {
     if (!self::$mounts) {
         \OC_Util::setupFS();
     }
     return self::$mounts->findByStorageId($id);
 }
コード例 #3
0
ファイル: encryption.php プロジェクト: rosarion/core
 /**
  * copy file between two storages
  *
  * @param Storage $sourceStorage
  * @param string $sourceInternalPath
  * @param string $targetInternalPath
  * @param bool $preserveMtime
  * @param bool $isRename
  * @return bool
  */
 private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename)
 {
     // first copy the keys that we reuse the existing file key on the target location
     // and don't create a new one which would break versions for example.
     $mount = $this->mountManager->findByStorageId($sourceStorage->getId());
     if (count($mount) === 1) {
         $mountPoint = $mount[0]->getMountPoint();
         $source = $mountPoint . '/' . $sourceInternalPath;
         $target = $this->getFullPath($targetInternalPath);
         $this->copyKeys($source, $target);
     } else {
         $this->logger->error('Could not find mount point, can\'t keep encryption keys');
     }
     if ($sourceStorage->is_dir($sourceInternalPath)) {
         $dh = $sourceStorage->opendir($sourceInternalPath);
         $result = $this->mkdir($targetInternalPath);
         if (is_resource($dh)) {
             while ($result and ($file = readdir($dh)) !== false) {
                 if (!Filesystem::isIgnoredDir($file)) {
                     $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file);
                 }
             }
         }
     } else {
         try {
             $source = $sourceStorage->fopen($sourceInternalPath, 'r');
             $target = $this->fopen($targetInternalPath, 'w');
             list(, $result) = \OC_Helper::streamCopy($source, $target);
             fclose($source);
             fclose($target);
         } catch (\Exception $e) {
             fclose($source);
             fclose($target);
             throw $e;
         }
         if ($result) {
             if ($preserveMtime) {
                 $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
             }
             $isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0;
             // in case of a rename we need to manipulate the source cache because
             // this information will be kept for the new target
             if ($isRename) {
                 $sourceStorage->getCache()->put($sourceInternalPath, ['encrypted' => $isEncrypted]);
             } else {
                 $this->getCache()->put($targetInternalPath, ['encrypted' => $isEncrypted]);
             }
         } else {
             // delete partially written target file
             $this->unlink($targetInternalPath);
             // delete cache entry that was created by fopen
             $this->getCache()->remove($targetInternalPath);
         }
     }
     return (bool) $result;
 }
コード例 #4
0
 public function testFindByStorageId()
 {
     /** @var \OCA\Files_External\Service\UserStoragesService $storageService */
     $storageService = $this->getMockBuilder('\\OCA\\Files_External\\Service\\UserStoragesService')->disableOriginalConstructor()->getMock();
     $storage = $this->getMockBuilder('\\OC\\Files\\Storage\\Storage')->disableOriginalConstructor()->getMock();
     $storage->expects($this->any())->method('getId')->will($this->returnValue('dummy'));
     $mount = new PersonalMount($storageService, 10, $storage, '/foo');
     $mountManager = new Manager();
     $mountManager->addMount($mount);
     $this->assertEquals([$mount], $mountManager->findByStorageId('dummy'));
 }
コード例 #5
0
ファイル: root.php プロジェクト: omusico/isle-web-framework
 /**
  * search file by id
  *
  * An array is returned because in the case where a single storage is mounted in different places the same file
  * can exist in different places
  *
  * @param int $id
  * @throws \OCP\Files\NotFoundException
  * @return Node[]
  */
 public function getById($id)
 {
     $result = Cache::getById($id);
     if (is_null($result)) {
         throw new NotFoundException();
     } else {
         list($storageId, $internalPath) = $result;
         $nodes = array();
         $mounts = $this->mountManager->findByStorageId($storageId);
         foreach ($mounts as $mount) {
             $nodes[] = $this->get($mount->getMountPoint() . $internalPath);
         }
         return $nodes;
     }
 }
コード例 #6
0
ファイル: root.php プロジェクト: adolfo2103/hcloudfilem
 /**
  * @param string $storageId
  * @return \OC\Files\Mount\MountPoint[]
  */
 public function getMountByStorageId($storageId)
 {
     return $this->mountManager->findByStorageId($storageId);
 }
コード例 #7
0
ファイル: Encryption.php プロジェクト: stweil/owncloud-core
 /**
  * copy file between two storages
  *
  * @param Storage $sourceStorage
  * @param string $sourceInternalPath
  * @param string $targetInternalPath
  * @param bool $preserveMtime
  * @param bool $isRename
  * @return bool
  * @throws \Exception
  */
 private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename)
 {
     // for versions we have nothing to do, because versions should always use the
     // key from the original file. Just create a 1:1 copy and done
     if ($this->isVersion($targetInternalPath) || $this->isVersion($sourceInternalPath)) {
         // remember that we try to create a version so that we can detect it during
         // fopen($sourceInternalPath) and by-pass the encryption in order to
         // create a 1:1 copy of the file
         $this->arrayCache->set('encryption_copy_version_' . $sourceInternalPath, true);
         $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
         $this->arrayCache->remove('encryption_copy_version_' . $sourceInternalPath);
         if ($result) {
             $info = $this->getCache('', $sourceStorage)->get($sourceInternalPath);
             // make sure that we update the unencrypted size for the version
             if (isset($info['encrypted']) && $info['encrypted'] === true) {
                 $this->updateUnencryptedSize($this->getFullPath($targetInternalPath), $info['size']);
             }
             $this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
         }
         return $result;
     }
     // first copy the keys that we reuse the existing file key on the target location
     // and don't create a new one which would break versions for example.
     $mount = $this->mountManager->findByStorageId($sourceStorage->getId());
     if (count($mount) === 1) {
         $mountPoint = $mount[0]->getMountPoint();
         $source = $mountPoint . '/' . $sourceInternalPath;
         $target = $this->getFullPath($targetInternalPath);
         $this->copyKeys($source, $target);
     } else {
         $this->logger->error('Could not find mount point, can\'t keep encryption keys');
     }
     if ($sourceStorage->is_dir($sourceInternalPath)) {
         $dh = $sourceStorage->opendir($sourceInternalPath);
         $result = $this->mkdir($targetInternalPath);
         if (is_resource($dh)) {
             while ($result and ($file = readdir($dh)) !== false) {
                 if (!Filesystem::isIgnoredDir($file)) {
                     $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file, false, $isRename);
                 }
             }
         }
     } else {
         try {
             $source = $sourceStorage->fopen($sourceInternalPath, 'r');
             $target = $this->fopen($targetInternalPath, 'w');
             list(, $result) = \OC_Helper::streamCopy($source, $target);
             fclose($source);
             fclose($target);
         } catch (\Exception $e) {
             fclose($source);
             fclose($target);
             throw $e;
         }
         if ($result) {
             if ($preserveMtime) {
                 $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
             }
             $this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
         } else {
             // delete partially written target file
             $this->unlink($targetInternalPath);
             // delete cache entry that was created by fopen
             $this->getCache()->remove($targetInternalPath);
         }
     }
     return (bool) $result;
 }