Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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);
     $normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
     $normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
     // rename to non-existing folder is denied
     if (!$this->view->file_exists($normalizedOldPath)) {
         $result['data'] = array('message' => $this->l10n->t('%s could not be renamed as it has been deleted', array($oldname)), 'code' => 'sourcenotfound', 'oldname' => $oldname, 'newname' => $newname);
     } else {
         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($normalizedNewPath)) {
                 $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($normalizedOldPath, $normalizedNewPath)) {
                     // successful rename
                     $meta = $this->view->getFileInfo($normalizedNewPath);
                     $meta = \OCA\Files\Helper::populateTags(array($meta));
                     $fileInfo = \OCA\Files\Helper::formatFileInfo(current($meta));
                     $fileInfo['path'] = dirname($normalizedNewPath);
                     $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;
 }
Example #3
0
 /**
  * Renames the node
  * @param string $name The new name
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\Forbidden
  */
 public function setName($name)
 {
     // rename is only allowed if the update privilege is granted
     if (!$this->info->isUpdateable()) {
         throw new \Sabre\DAV\Exception\Forbidden();
     }
     list($parentPath, ) = \Sabre\HTTP\URLUtil::splitPath($this->path);
     list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name);
     // verify path of the target
     $this->verifyPath();
     $newPath = $parentPath . '/' . $newName;
     $this->fileView->rename($this->path, $newPath);
     $this->path = $newPath;
     $this->refreshInfo();
 }
Example #4
0
 /**
  * rename file keys
  *
  * @param string $user
  * @param string $path
  * @param bool $trash
  */
 private function renameFileKeys($user, $path, $trash = false)
 {
     if ($this->view->is_dir($user . '/' . $path) === false) {
         $this->logger->info('Skip dir /' . $user . '/' . $path . ': does not exist');
         return;
     }
     $dh = $this->view->opendir($user . '/' . $path);
     if (is_resource($dh)) {
         while (($file = readdir($dh)) !== false) {
             if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
                 if ($this->view->is_dir($user . '/' . $path . '/' . $file)) {
                     $this->renameFileKeys($user, $path . '/' . $file, $trash);
                 } else {
                     $target = $this->getTargetDir($user, $path, $file, $trash);
                     if ($target) {
                         $this->createPathForKeys(dirname($target));
                         $this->view->rename($user . '/' . $path . '/' . $file, $target);
                     } else {
                         $this->logger->warning('did not move key "' . $file . '" could not find the corresponding file in /data/' . $user . '/files.' . 'Most likely the key was already moved in a previous migration run and is already on the right place.');
                     }
                 }
             }
         }
         closedir($dh);
     }
 }
Example #5
0
 /**
  * Test that versions are not auto-trashed when moving a file between
  * storages. This is because rename() between storages would call
  * unlink() which should NOT trigger the version deletion logic.
  */
 public function testKeepFileAndVersionsWhenMovingFolderBetweenStorages()
 {
     \OCA\Files_Versions\Hooks::connectHooks();
     $storage2 = new Temporary(array());
     \OC\Files\Filesystem::mount($storage2, array(), $this->user . '/files/substorage');
     // trigger a version (multiple would not work because of the expire logic)
     $this->userView->file_put_contents('folder/inside.txt', 'v1');
     $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
     $this->assertEquals(0, count($results));
     $results = $this->rootView->getDirectoryContent($this->user . '/files_versions/folder/');
     $this->assertEquals(1, count($results));
     // move to another storage
     $this->userView->rename('folder', 'substorage/folder');
     $this->assertTrue($this->userView->file_exists('substorage/folder/inside.txt'));
     // rescan trash storage
     list($rootStorage, ) = $this->rootView->resolvePath($this->user . '/files_trashbin');
     $rootStorage->getScanner()->scan('');
     // versions were moved too
     $results = $this->rootView->getDirectoryContent($this->user . '/files_versions/substorage/folder/');
     $this->assertEquals(1, count($results));
     // check that nothing got trashed by the rename's unlink() call
     $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/files');
     $this->assertEquals(0, count($results));
     // check that versions were moved and not trashed
     $results = $this->rootView->getDirectoryContent($this->user . '/files_trashbin/versions/');
     $this->assertEquals(0, count($results));
 }
Example #6
0
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\Forbidden
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $targetNodeExists = $this->nodeExists($destinationPath);
     $sourceNode = $this->getNodeForPath($sourcePath);
     if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) {
         throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode->getName() . ', target exists');
     }
     list($sourceDir, ) = \Sabre\HTTP\URLUtil::splitPath($sourcePath);
     list($destinationDir, ) = \Sabre\HTTP\URLUtil::splitPath($destinationPath);
     $isMovableMount = false;
     $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath));
     $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath));
     if ($sourceMount instanceof MoveableMount && $internalPath === '') {
         $isMovableMount = true;
     }
     try {
         $sameFolder = $sourceDir === $destinationDir;
         // if we're overwriting or same folder
         if ($targetNodeExists || $sameFolder) {
             // note that renaming a share mount point is always allowed
             if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         } else {
             if (!$this->fileView->isCreatable($destinationDir)) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         if (!$sameFolder) {
             // moving to a different folder, source will be gone, like a deletion
             // note that moving a share mount point is always allowed
             if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         $fileName = basename($destinationPath);
         try {
             $this->fileView->verifyPath($destinationDir, $fileName);
         } catch (\OCP\Files\InvalidPathException $ex) {
             throw new InvalidPath($ex->getMessage());
         }
         $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
         if (!$renameOkay) {
             throw new \Sabre\DAV\Exception\Forbidden('');
         }
     } 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);
     }
     $this->markDirty($sourceDir);
     $this->markDirty($destinationDir);
 }
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\Forbidden
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $targetNodeExists = $this->nodeExists($destinationPath);
     $sourceNode = $this->getNodeForPath($sourcePath);
     if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) {
         throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode . ', target exists');
     }
     list($sourceDir, ) = \Sabre\DAV\URLUtil::splitPath($sourcePath);
     list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destinationPath);
     $isMovableMount = false;
     $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath));
     $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath));
     if ($sourceMount instanceof MoveableMount && $internalPath === '') {
         $isMovableMount = true;
     }
     try {
         $sameFolder = $sourceDir === $destinationDir;
         // if we're overwriting or same folder
         if ($targetNodeExists || $sameFolder) {
             // note that renaming a share mount point is always allowed
             if (!$this->fileView->isUpdatable($destinationDir) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         } else {
             if (!$this->fileView->isCreatable($destinationDir)) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         if (!$sameFolder) {
             // moving to a different folder, source will be gone, like a deletion
             // note that moving a share mount point is always allowed
             if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         $fileName = basename($destinationPath);
         if (!\OCP\Util::isValidFileName($fileName)) {
             throw new \Sabre\DAV\Exception\BadRequest();
         }
         $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
         if (!$renameOkay) {
             throw new \Sabre\DAV\Exception\Forbidden('');
         }
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
     }
     // update properties
     $query = \OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?');
     $query->execute(array(\OC\Files\Filesystem::normalizePath($destinationPath), \OC_User::getUser(), \OC\Files\Filesystem::normalizePath($sourcePath)));
     $this->markDirty($sourceDir);
     $this->markDirty($destinationDir);
 }
Example #8
0
 /**
  * move keys if a file was renamed
  *
  * @param string $source
  * @param string $target
  * @return boolean
  */
 public function renameKeys($source, $target)
 {
     $sourcePath = $this->getPathToKeys($source);
     $targetPath = $this->getPathToKeys($target);
     if ($this->view->file_exists($sourcePath)) {
         $this->keySetPreparation(dirname($targetPath));
         $this->view->rename($sourcePath, $targetPath);
         return true;
     }
     return false;
 }
Example #9
0
	public function testMoveFolderCrossStorage() {
		$storage2 = new Temporary(array());
		$cache2 = $storage2->getCache();
		Filesystem::mount($storage2, array(), '/bar');
		$this->storage->mkdir('foo');
		$this->storage->mkdir('foo/bar');
		$this->storage->file_put_contents('foo/foo.txt', 'qwerty');
		$this->storage->file_put_contents('foo/bar.txt', 'foo');
		$this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop');

		$this->storage->getScanner()->scan('');

		$this->assertTrue($this->cache->inCache('foo'));
		$this->assertTrue($this->cache->inCache('foo/foo.txt'));
		$this->assertTrue($this->cache->inCache('foo/bar.txt'));
		$this->assertTrue($this->cache->inCache('foo/bar'));
		$this->assertTrue($this->cache->inCache('foo/bar/bar.txt'));
		$cached = [];
		$cached[] = $this->cache->get('foo');
		$cached[] = $this->cache->get('foo/foo.txt');
		$cached[] = $this->cache->get('foo/bar.txt');
		$cached[] = $this->cache->get('foo/bar');
		$cached[] = $this->cache->get('foo/bar/bar.txt');

		// add extension to trigger the possible mimetype change
		$this->view->rename('/foo', '/bar/foo.b');

		$this->assertFalse($this->cache->inCache('foo'));
		$this->assertFalse($this->cache->inCache('foo/foo.txt'));
		$this->assertFalse($this->cache->inCache('foo/bar.txt'));
		$this->assertFalse($this->cache->inCache('foo/bar'));
		$this->assertFalse($this->cache->inCache('foo/bar/bar.txt'));
		$this->assertTrue($cache2->inCache('foo.b'));
		$this->assertTrue($cache2->inCache('foo.b/foo.txt'));
		$this->assertTrue($cache2->inCache('foo.b/bar.txt'));
		$this->assertTrue($cache2->inCache('foo.b/bar'));
		$this->assertTrue($cache2->inCache('foo.b/bar/bar.txt'));

		$cachedTarget = [];
		$cachedTarget[] = $cache2->get('foo.b');
		$cachedTarget[] = $cache2->get('foo.b/foo.txt');
		$cachedTarget[] = $cache2->get('foo.b/bar.txt');
		$cachedTarget[] = $cache2->get('foo.b/bar');
		$cachedTarget[] = $cache2->get('foo.b/bar/bar.txt');

		foreach ($cached as $i => $old) {
			$new = $cachedTarget[$i];
			$this->assertEquals($old['mtime'], $new['mtime']);
			$this->assertEquals($old['size'], $new['size']);
			$this->assertEquals($old['etag'], $new['etag']);
			$this->assertEquals($old['fileid'], $new['fileid']);
			$this->assertEquals($old['mimetype'], $new['mimetype']);
		}
	}
Example #10
0
 /**
  * move user encryption folder to new root folder
  *
  * @param string $user
  * @param string $oldRoot
  * @param string $newRoot
  * @throws \Exception
  */
 protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot)
 {
     if ($this->userManager->userExists($user)) {
         $source = $oldRoot . '/' . $user . '/files_encryption';
         $target = $newRoot . '/' . $user . '/files_encryption';
         if ($this->rootView->is_dir($source) && $this->targetExists($target) === false) {
             $this->prepareParentFolder($newRoot . '/' . $user);
             $this->rootView->rename($source, $target);
         }
     }
 }
Example #11
0
 function testDescryptAllWithBrokenFiles()
 {
     $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt";
     $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt";
     $util = new \OCA\Files_Encryption\Util($this->view, $this->userId);
     $this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort);
     $this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort);
     $fileInfoEncrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoEncrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue($fileInfoEncrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoEncrypted2 instanceof \OC\Files\FileInfo);
     $this->assertEquals($fileInfoEncrypted1['encrypted'], 1);
     $this->assertEquals($fileInfoEncrypted2['encrypted'], 1);
     // rename keyfile for file1 so that the decryption for file1 fails
     // Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway
     $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved');
     // need to reset key cache that we don't use the cached key
     $this->resetKeyCache();
     // decrypt all encrypted files
     $result = $util->decryptAll();
     $this->assertFalse($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
     // file1 should be still encrypted; file2 should be decrypted
     $this->assertEquals(1, $fileInfoUnencrypted1['encrypted']);
     $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
     // keyfiles and share keys should still exist
     $this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keys/'));
     $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved'));
     $this->assertTrue($this->view->file_exists($this->userId . '/files_encryption/keys/' . $file1 . '/' . $this->userId . '.shareKey'));
     // rename the keyfile for file1 back
     $this->view->rename($this->userId . '/files_encryption/keys/' . $file1 . '/fileKey.moved', $this->userId . '/files_encryption/keys/' . $file1 . '/fileKey');
     // try again to decrypt all encrypted files
     $result = $util->decryptAll();
     $this->assertTrue($result);
     $fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
     $fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
     $this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
     $this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
     // now both files should be decrypted
     $this->assertEquals(0, $fileInfoUnencrypted1['encrypted']);
     $this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
     // keyfiles and share keys should be deleted
     $this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keys/'));
     //cleanup
     $backupPath = $this->getBackupPath('decryptAll');
     $this->view->unlink($this->userId . '/files/' . $file1);
     $this->view->unlink($this->userId . '/files/' . $file2);
     $this->view->deleteAll($backupPath);
 }
Example #12
0
 /**
  * @medium
  */
 function testFailShareFile()
 {
     // login as admin
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertInternalType('int', $cryptedFile);
     // disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // check if we have a valid file info
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
     // check if the unencrypted file size is stored
     $this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
     // break users public key
     $this->view->rename(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', \OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup');
     // re-enable the file proxy
     \OC_FileProxy::$enabled = $proxyStatus;
     // share the file
     try {
         \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL);
     } catch (\Exception $e) {
         $this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption"));
     }
     // login as admin
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // check if share key for user1 not exists
     $this->assertFalse($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
     // disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // break user1 public key
     $this->view->rename(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', \OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey');
     // remove share file
     $this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey');
     // re-enable the file proxy
     \OC_FileProxy::$enabled = $proxyStatus;
     // unshare the file with user1
     \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1);
     // check if share key not exists
     $this->assertFalse($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
     // cleanup
     $this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
     $this->view->unlink($this->filename);
     $this->view->chroot('/');
 }
Example #13
0
 /**
  * restore backup
  *
  * @param string $backup complete name of the backup
  * @return boolean
  */
 public function restoreBackup($backup)
 {
     $backupDir = $this->encryptionDir . '/backup.' . $backup . '/';
     $fileKeysRestored = $this->view->rename($backupDir . 'keys', $this->encryptionDir . '/keys');
     $pubKeyRestored = $privKeyRestored = true;
     if ($this->view->file_exists($backupDir . $this->userId . '.privateKey') && $this->view->file_exists($backupDir . $this->userId . '.privateKey')) {
         $pubKeyRestored = $this->view->rename($backupDir . $this->userId . '.publicKey', $this->publicKeyPath);
         $privKeyRestored = $this->view->rename($backupDir . $this->userId . '.privateKey', $this->privateKeyPath);
     }
     if ($fileKeysRestored && $pubKeyRestored && $privKeyRestored) {
         $this->view->deleteAll($backupDir);
         return true;
     }
     return false;
 }
Example #14
0
 /**
  * @param OCP\Files\FileInfo[] $files
  * @param string $trashRoot
  * @param integer $expireDate
  */
 private function manipulateDeleteTime($files, $trashRoot, $expireDate)
 {
     $counter = 0;
     foreach ($files as &$file) {
         // modify every second file
         $counter = ($counter + 1) % 2;
         if ($counter === 1) {
             $source = $trashRoot . '/files/' . $file['name'] . '.d' . $file['mtime'];
             $target = \OC\Files\Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
             $this->rootView->rename($source, $target);
             $file['mtime'] = $expireDate;
         }
     }
     return \OCA\Files\Helper::sortFiles($files, 'mtime');
 }
Example #15
0
 /**
  * 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;
 }
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\Forbidden
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $sourceNode = $this->getNodeForPath($sourcePath);
     if ($sourceNode instanceof \Sabre\DAV\ICollection and $this->nodeExists($destinationPath)) {
         throw new \Sabre\DAV\Exception\Forbidden('Could not copy directory ' . $sourceNode . ', target exists');
     }
     list($sourceDir, ) = \Sabre\DAV\URLUtil::splitPath($sourcePath);
     list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destinationPath);
     $isMovableMount = false;
     $sourceMount = $this->mountManager->find($this->fileView->getAbsolutePath($sourcePath));
     $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath));
     if ($sourceMount instanceof MoveableMount && $internalPath === '') {
         $isMovableMount = true;
     }
     try {
         // check update privileges
         if (!$this->fileView->isUpdatable($sourcePath) && !$isMovableMount) {
             throw new \Sabre\DAV\Exception\Forbidden();
         }
         if ($sourceDir !== $destinationDir) {
             if (!$this->fileView->isCreatable($destinationDir)) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
             if (!$this->fileView->isDeletable($sourcePath) && !$isMovableMount) {
                 throw new \Sabre\DAV\Exception\Forbidden();
             }
         }
         $fileName = basename($destinationPath);
         if (!\OCP\Util::isValidFileName($fileName)) {
             throw new \Sabre\DAV\Exception\BadRequest();
         }
         $renameOkay = $this->fileView->rename($sourcePath, $destinationPath);
         if (!$renameOkay) {
             throw new \Sabre\DAV\Exception\Forbidden('');
         }
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
     }
     // update properties
     $query = \OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?');
     $query->execute(array(\OC\Files\Filesystem::normalizePath($destinationPath), \OC_User::getUser(), \OC\Files\Filesystem::normalizePath($sourcePath)));
     $this->markDirty($sourceDir);
     $this->markDirty($destinationDir);
 }
Example #17
0
 /**
  * move keys if a file was renamed
  *
  * @param string $source
  * @param string $target
  * @param string $owner
  * @param bool $systemWide
  */
 public function renameKeys($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->rename($sourcePath, $targetPath);
     }
 }
Example #18
0
 /**
  * rename file keys
  *
  * @param string $user
  * @param string $path
  * @param bool $trash
  */
 private function renameFileKeys($user, $path, $trash = false)
 {
     $dh = $this->view->opendir($user . '/' . $path);
     if (is_resource($dh)) {
         while (($file = readdir($dh)) !== false) {
             if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
                 if ($this->view->is_dir($user . '/' . $path . '/' . $file)) {
                     $this->renameFileKeys($user, $path . '/' . $file, $trash);
                 } else {
                     $target = $this->getTargetDir($user, $path, $file, $trash);
                     $this->createPathForKeys(dirname($target));
                     $this->view->rename($user . '/' . $path . '/' . $file, $target);
                 }
             }
         }
         closedir($dh);
     }
 }
Example #19
0
	/**
	 * test rename operation
	 */
	function doTestRenameHook($filename) {
		// check if keys exists
		$this->assertTrue($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
			. $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));

		$this->assertTrue($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
			. $filename . '.key'));

		// make subfolder and sub-subfolder
		$this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
		$this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder);

		$this->assertTrue($this->rootView->is_dir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder));

		// move the file to the sub-subfolder
		$root = $this->rootView->getRoot();
		$this->rootView->chroot('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/');
		$this->rootView->rename($filename, '/' . $this->folder . '/' . $this->folder . '/' . $filename);
		$this->rootView->chroot($root);

		$this->assertFalse($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $filename));
		$this->assertTrue($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->folder . '/' . $filename));

		// keys should be renamed too
		$this->assertFalse($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
			. $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
		$this->assertFalse($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/'
			. $filename . '.key'));

		$this->assertTrue($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->folder . '/' . $this->folder . '/'
			. $filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
		$this->assertTrue($this->rootView->file_exists(
			'/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->folder . '/' . $this->folder . '/'
			. $filename . '.key'));

		// cleanup
		$this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder);
	}
Example #20
0
 /**
  * Renames the node
  * @param string $name The new name
  * @throws \Sabre\DAV\Exception\BadRequest
  * @throws \Sabre\DAV\Exception\Forbidden
  */
 public function setName($name)
 {
     // rename is only allowed if the update privilege is granted
     if (!$this->info->isUpdateable()) {
         throw new \Sabre\DAV\Exception\Forbidden();
     }
     list($parentPath, ) = URLUtil::splitPath($this->path);
     list(, $newName) = URLUtil::splitPath($name);
     if (!\OCP\Util::isValidFileName($newName)) {
         throw new \Sabre\DAV\Exception\BadRequest();
     }
     $newPath = $parentPath . '/' . $newName;
     $oldPath = $this->path;
     $this->fileView->rename($this->path, $newPath);
     $this->path = $newPath;
     $query = OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' . ' WHERE `userid` = ? AND `propertypath` = ?');
     $query->execute(array($newPath, OC_User::getUser(), $oldPath));
     $this->refreshInfo();
 }
Example #21
0
 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->rename($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey');
                     }
                 }
             }
         }
         closedir($dh);
     }
 }
Example #22
0
 public function testMigrateToNewFolderStructure()
 {
     // go back to the state before migration
     $this->view->rename('/files_encryption/public_keys', '/public-keys');
     $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.public.key');
     $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.public.key');
     $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.public.key');
     $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/keys');
     $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/keys');
     $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/keys');
     $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
     $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
     $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key');
     $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER1);
     $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER2);
     $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER3);
     $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER1);
     $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER2);
     $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER3);
     $this->createDummyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2);
     // no user for system wide mount points
     $this->createDummyFileKeys('');
     $this->createDummyShareKeys('');
     $this->createDummySystemWideKeys();
     $m = new \OCA\Files_Encryption\Migration();
     $m->reorganizeFolderStructure();
     // TODO Verify that all files at the right place
     $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey'));
     $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey'));
     $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey'));
     $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER1);
     $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER2);
     $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER3);
     // system wide keys
     $this->verifyNewKeyPath('');
     // trash
     $this->verifyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2);
 }
 public function testPropagateWhenRemovedFromGroupWithSubdirTarget()
 {
     $this->recipientGroup->addUser($this->recipientUser);
     // relogin to refresh mount points
     $this->loginAsUser($this->recipientUser->getUID());
     $recipientView = new View('/' . $this->recipientUser->getUID() . '/files');
     $this->assertTrue($recipientView->mkdir('sub'));
     $this->assertTrue($recipientView->rename('folder', 'sub/folder'));
     $this->propagationManager->expects($this->once())->method('propagateSharesToUser')->with($this->callback(function ($shares) {
         if (count($shares) !== 1) {
             return false;
         }
         $share = array_values($shares)[0];
         return $share['file_source'] === $this->fileInfo['fileid'] && $share['share_with'] === $this->recipientGroup->getGID() && $share['file_target'] === '/sub/folder';
     }), $this->recipientUser->getUID());
     $this->recipientGroup->removeUser($this->recipientUser);
 }
 /**
  * "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
  * "user2" receives the folder and puts it in "sub1/sub2/folder"
  * "user3" receives the folder and puts it in "sub1/sub2/folder"
  * "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
  * "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
  */
 protected function setUpShares()
 {
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
     $rootFolder = \OC::$server->getRootFolder();
     $shareManager = \OC::$server->getShareManager();
     $this->rootView = new View('');
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('/sub1/sub2/folder/inside');
     $view1->mkdir('/directReshare');
     $view1->mkdir('/sub1/sub2/folder/other');
     $view1->file_put_contents('/foo.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
     $folderInfo = $view1->getFileInfo('/sub1/sub2/folder');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $folderInfo);
     $fileInfo = $view1->getFileInfo('/foo.txt');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $fileInfo);
     $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/foo.txt');
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     $shareManager->createShare($share);
     $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $shareManager->createShare($share);
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER3)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $shareManager->createShare($share);
     $folderInfo = $view1->getFileInfo('/directReshare');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $folderInfo);
     $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/directReshare');
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $shareManager->createShare($share);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
     /*
      * User 2
      */
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $view2->mkdir('/sub1/sub2');
     $view2->rename('/folder', '/sub1/sub2/folder');
     $insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $insideInfo);
     $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get('/sub1/sub2/folder/inside');
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER4)->setSharedBy(self::TEST_FILES_SHARING_API_USER2)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $shareManager->createShare($share);
     $folderInfo = $view2->getFileInfo('/directReshare');
     $this->assertInstanceOf('\\OC\\Files\\FileInfo', $folderInfo);
     $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get('/directReshare');
     $share = $shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER4)->setSharedBy(self::TEST_FILES_SHARING_API_USER2)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $shareManager->createShare($share);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
     /*
      * User 3
      */
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $view3->mkdir('/sub1/sub2');
     $view3->rename('/folder', '/sub1/sub2/folder');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
     /*
      * User 4
      */
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
     $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
     $view4->mkdir('/sub1/sub2');
     $view4->rename('/inside', '/sub1/sub2/inside');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
     foreach ($this->fileIds as $user => $ids) {
         $this->loginAsUser($user);
         foreach ($ids as $id) {
             $path = $this->rootView->getPath($id);
             $ls = $this->rootView->getDirectoryContent($path);
             $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
         }
     }
 }
Example #25
0
 /**
  * restore versions from trash bin
  *
  * @param \OC\Files\View $view file view
  * @param string $file complete path to file
  * @param string $filename name of file once it was deleted
  * @param string $uniqueFilename new file name to restore the file without overwriting existing files
  * @param string $location location if file
  * @param int $timestamp deletion time
  * @return bool
  */
 private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp)
 {
     if (\OCP\App::isEnabled('files_versions')) {
         $user = \OCP\User::getUser();
         $rootView = new \OC\Files\View('/');
         $target = \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename);
         list($owner, $ownerPath) = self::getUidAndFilename($target);
         // file has been deleted in between
         if (empty($ownerPath)) {
             return false;
         }
         if ($timestamp) {
             $versionedFile = $filename;
         } else {
             $versionedFile = $file;
         }
         if ($view->is_dir('/files_trashbin/versions/' . $file)) {
             $rootView->rename(\OC\Files\Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath));
         } else {
             if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp, $user)) {
                 foreach ($versions as $v) {
                     if ($timestamp) {
                         $rootView->rename($user . '/files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, $owner . '/files_versions/' . $ownerPath . '.v' . $v);
                     } else {
                         $rootView->rename($user . '/files_trashbin/versions/' . $versionedFile . '.v' . $v, $owner . '/files_versions/' . $ownerPath . '.v' . $v);
                     }
                 }
             }
         }
     }
 }
Example #26
0
 /**
  * "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
  * "user2" receives the folder and puts it in "sub1/sub2/folder"
  * "user3" receives the folder and puts it in "sub1/sub2/folder"
  * "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
  * "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
  */
 private function setUpShares()
 {
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
     $this->rootView = new View('');
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('/sub1/sub2/folder/inside');
     $view1->mkdir('/directReshare');
     $view1->mkdir('/sub1/sub2/folder/other');
     $view1->mkdir('/sub1/sub2/folder/other');
     $view1->file_put_contents('/foo.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
     $view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
     $folderInfo = $view1->getFileInfo('/sub1/sub2/folder');
     $fileInfo = $view1->getFileInfo('/foo.txt');
     \OCP\Share::shareItem('file', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     $folderInfo = $view1->getFileInfo('/directReshare');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $view2->mkdir('/sub1/sub2');
     $view2->rename('/folder', '/sub1/sub2/folder');
     $insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
     \OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
     $folderInfo = $view2->getFileInfo('/directReshare');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $view3->mkdir('/sub1/sub2');
     $view3->rename('/folder', '/sub1/sub2/folder');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
     $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
     $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
     $view4->mkdir('/sub1/sub2');
     $view4->rename('/inside', '/sub1/sub2/inside');
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
     $this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
     foreach ($this->fileIds as $user => $ids) {
         $this->loginAsUser($user);
         foreach ($ids as $id) {
             $path = $this->rootView->getPath($id);
             $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
         }
     }
 }
Example #27
0
 public static function rename($path1, $path2)
 {
     return self::$defaultInstance->rename($path1, $path2);
 }
Example #28
0
 /**
  * @param OutputInterface $output
  */
 protected function transfer(OutputInterface $output)
 {
     $view = new View();
     $output->writeln("Transferring files to {$this->finalTarget} ...");
     $view->rename("{$this->sourceUser}/files", $this->finalTarget);
     // because the files folder is moved away we need to recreate it
     $view->mkdir("{$this->sourceUser}/files");
 }
Example #29
0
 private function renameUsersPrivateKey($user)
 {
     $oldPrivateKey = $user . '/files_encryption/' . $user . '.private.key';
     $newPrivateKey = substr($oldPrivateKey, 0, strlen($oldPrivateKey) - strlen('.private.key')) . '.privateKey';
     $this->view->rename($oldPrivateKey, $newPrivateKey);
 }