Example #1
0
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $textData = "dummy file data\n";
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddirrestricted');
     $this->view->mkdir('container/shareddirrestricted/subdir');
     $this->view->file_put_contents('container/shareddir/textfile.txt', $textData);
     $this->view->file_put_contents('container/shareddirrestricted/textfile1.txt', $textData);
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
     \OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 7);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $this->secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $this->secondView->resolvePath('files/shareddir');
     list($this->sharedStorageRestrictedShare, $internalPath) = $this->secondView->resolvePath('files/shareddirrestricted');
     $this->sharedCache = $this->sharedStorage->getCache();
     $this->sharedCacheRestrictedShare = $this->sharedStorageRestrictedShare->getCache();
 }
Example #2
0
 public function setUp()
 {
     // remember files_encryption state
     $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
     // we want to tests with the encryption app disabled
     \OC_App::disable('files_encryption');
     $this->storage = new \OC\Files\Storage\Temporary(array());
     $textData = "dummy file data\n";
     $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
     $this->storage->mkdir('folder');
     $this->storage->file_put_contents('foo.txt', $textData);
     $this->storage->file_put_contents('foo.png', $imgData);
     $this->storage->file_put_contents('folder/bar.txt', $textData);
     $this->storage->file_put_contents('folder/bar2.txt', $textData);
     $this->scanner = $this->storage->getScanner();
     $this->scanner->scan('');
     $this->cache = $this->storage->getCache();
     \OC\Files\Filesystem::tearDown();
     if (!self::$user) {
         self::$user = uniqid();
     }
     \OC_User::createUser(self::$user, 'password');
     \OC_User::setUserId(self::$user);
     \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
     Filesystem::clearMounts();
     Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
     \OC_Hook::clear('OC_Filesystem');
 }
Example #3
0
	protected function setUp() {
		parent::setUp();

		$this->storage = new \OC\Files\Storage\Temporary(array());
		$textData = "dummy file data\n";
		$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
		$this->storage->mkdir('folder');
		$this->storage->file_put_contents('foo.txt', $textData);
		$this->storage->file_put_contents('foo.png', $imgData);
		$this->storage->file_put_contents('folder/bar.txt', $textData);
		$this->storage->file_put_contents('folder/bar2.txt', $textData);

		$this->scanner = $this->storage->getScanner();
		$this->scanner->scan('');
		$this->cache = $this->storage->getCache();

		if (!self::$user) {
			self::$user = $this->getUniqueID();
		}

		\OC_User::createUser(self::$user, 'password');
		$this->loginAsUser(self::$user);

		Filesystem::init(self::$user, '/' . self::$user . '/files');

		Filesystem::clearMounts();
		Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');

		\OC_Hook::clear('OC_Filesystem');
	}
Example #4
0
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $textData = "dummy file data\n";
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddirrestricted');
     $this->view->mkdir('container/shareddirrestricted/subdir');
     $this->view->file_put_contents('container/shareddir/textfile.txt', $textData);
     $this->view->file_put_contents('container/shareddirrestricted/textfile1.txt', $textData);
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
     $node = $rootFolder->get('container/shareddir');
     $share = $this->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);
     $this->shareManager->createShare($share);
     $node = $rootFolder->get('container/shareddirrestricted');
     $share = $this->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_CREATE | \OCP\Constants::PERMISSION_UPDATE);
     $this->shareManager->createShare($share);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $this->secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $this->secondView->resolvePath('files/shareddir');
     list($this->sharedStorageRestrictedShare, $internalPath) = $this->secondView->resolvePath('files/shareddirrestricted');
     $this->sharedCache = $this->sharedStorage->getCache();
     $this->sharedCacheRestrictedShare = $this->sharedStorageRestrictedShare->getCache();
 }
Example #5
0
 function setUp()
 {
     parent::setUp();
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One');
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // prepare user1's dir structure
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddir/emptydir');
     $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $this->view->file_put_contents('container/not shared.txt', $textData);
     $this->view->file_put_contents('container/shared single file.txt', $textData);
     $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
     list($this->ownerStorage, ) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
     \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, ) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Example #6
0
 /**
  * @param \OC\Files\Storage\Storage $storage
  */
 public function __construct(\OC\Files\Storage\Storage $storage)
 {
     $this->storage = $storage;
     $this->propagator = $storage->getPropagator();
     $this->scanner = $storage->getScanner();
     $this->cache = $storage->getCache();
 }
Example #7
0
 /**
  * get a scanner instance for the storage
  *
  * @param string $path
  * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
  * @return \OC\Files\Cache\Scanner
  */
 public function getScanner($path = '', $storage = null)
 {
     if (!$storage) {
         $storage = $this;
     }
     return $this->storage->getScanner($path, $storage);
 }
Example #8
0
 /**
  * Adds the test file to the filesystem
  *
  * @param string $fileName name of the file to create
  * @param string $fileContent path to file to use for test
  *
  * @return string
  */
 protected function prepareTestFile($fileName, $fileContent)
 {
     $imgData = file_get_contents($fileContent);
     $imgPath = '/' . $this->userId . '/files/' . $fileName;
     $this->rootView->file_put_contents($imgPath, $imgData);
     $scanner = $this->storage->getScanner();
     $scanner->scan('');
     return $imgPath;
 }
Example #9
0
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $this->_share = $this->share(\OCP\Share::SHARE_TYPE_USER, 'container/shareddir', self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Example #10
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 #11
0
 public function testParentSize()
 {
     $this->storage->getScanner()->scan('');
     $parentCached = $this->cache->get('');
     $this->assertEquals(0, $parentCached['size']);
     $this->storage->file_put_contents('foo.txt', 'bar');
     $parentCached = $this->cache->get('');
     $this->assertEquals(0, $parentCached['size']);
     $this->updater->update('foo.txt');
     $parentCached = $this->cache->get('');
     $this->assertEquals(3, $parentCached['size']);
     $this->storage->file_put_contents('foo.txt', 'qwerty');
     $parentCached = $this->cache->get('');
     $this->assertEquals(3, $parentCached['size']);
     $this->updater->update('foo.txt');
     $parentCached = $this->cache->get('');
     $this->assertEquals(6, $parentCached['size']);
     $this->storage->unlink('foo.txt');
     $parentCached = $this->cache->get('');
     $this->assertEquals(6, $parentCached['size']);
     $this->updater->remove('foo.txt');
     $parentCached = $this->cache->get('');
     $this->assertEquals(0, $parentCached['size']);
 }
Example #12
0
 /**
  * Test searching by tag for multiple sections of the tree
  */
 function testSearchByTagTree()
 {
     $userId = \OC::$server->getUserSession()->getUser()->getUId();
     $this->sharedStorage->mkdir('subdir/emptydir');
     $this->sharedStorage->mkdir('subdir/emptydir2');
     $this->ownerStorage->getScanner()->scan('');
     $allIds = array($this->sharedCache->get('')['fileid'], $this->sharedCache->get('bar.txt')['fileid'], $this->sharedCache->get('subdir/another too.txt')['fileid'], $this->sharedCache->get('subdir/not a text file.xml')['fileid'], $this->sharedCache->get('subdir/another.txt')['fileid'], $this->sharedCache->get('subdir/emptydir')['fileid'], $this->sharedCache->get('subdir/emptydir2')['fileid']);
     $tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId);
     foreach ($allIds as $id) {
         $tagManager->tagAs($id, 'tag1');
     }
     $results = $this->sharedStorage->getCache()->searchByTag('tag1', $userId);
     $check = array(array('name' => 'shareddir', 'path' => ''), array('name' => 'bar.txt', 'path' => 'bar.txt'), array('name' => 'another.txt', 'path' => 'subdir/another.txt'), array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'), array('name' => 'emptydir', 'path' => 'subdir/emptydir'), array('name' => 'emptydir2', 'path' => 'subdir/emptydir2'), array('name' => 'not a text file.xml', 'path' => 'subdir/not a text file.xml'));
     $this->verifyFiles($check, $results);
     $tagManager->delete(array('tag1'));
 }
Example #13
0
 /**
  * Get file info from cache
  *
  * If the file is not in cached it will be scanned
  * If the file has changed on storage the cache will be updated
  *
  * @param \OC\Files\Storage\Storage $storage
  * @param string $internalPath
  * @param string $relativePath
  * @return array|bool
  */
 private function getCacheEntry($storage, $internalPath, $relativePath)
 {
     $cache = $storage->getCache($internalPath);
     $data = $cache->get($internalPath);
     $watcher = $storage->getWatcher($internalPath);
     try {
         // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
         if (!$data || $data['size'] === -1) {
             $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
             if (!$storage->file_exists($internalPath)) {
                 $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
                 return false;
             }
             $scanner = $storage->getScanner($internalPath);
             $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
             $data = $cache->get($internalPath);
             $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
         } else {
             if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
                 $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
                 $watcher->update($internalPath, $data);
                 $storage->getPropagator()->propagateChange($internalPath, time());
                 $data = $cache->get($internalPath);
                 $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
             }
         }
     } catch (LockedException $e) {
         // if the file is locked we just use the old cache info
     }
     return $data;
 }
Example #14
0
 /**
  * get a scanner instance for the storage
  *
  * @param string $path
  * @return \OC\Files\Cache\Scanner
  */
 public function getScanner($path = '')
 {
     return $this->storage->getScanner($path);
 }