public function testOC() { $originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); $storage->file_put_contents('foo.txt', 'asd'); \OC\Files\Filesystem::mount($storage, array(), '/'); $this->assertTrue(file_exists('oc:///foo.txt')); $this->assertEquals('asd', file_get_contents('oc:///foo.txt')); $this->assertEquals(array('.', '..', 'foo.txt'), scandir('oc:///')); file_put_contents('oc:///bar.txt', 'qwerty'); $this->assertEquals('qwerty', $storage->file_get_contents('bar.txt')); $this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///')); $this->assertEquals('qwerty', file_get_contents('oc:///bar.txt')); $fh = fopen('oc:///bar.txt', 'rb'); $this->assertSame(0, ftell($fh)); $content = fread($fh, 4); $this->assertSame(4, ftell($fh)); $this->assertSame('qwer', $content); $content = fread($fh, 1); $this->assertSame(5, ftell($fh)); $this->assertSame(0, fseek($fh, 0)); $this->assertSame(0, ftell($fh)); unlink('oc:///foo.txt'); $this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///')); \OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::mount($originalStorage, array(), '/'); }
public function testOC() { // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout() // (would currently break the tests for some reason) $originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); $storage->file_put_contents('foo.txt', 'asd'); \OC\Files\Filesystem::mount($storage, array(), '/'); $this->assertTrue(file_exists('oc:///foo.txt')); $this->assertEquals('asd', file_get_contents('oc:///foo.txt')); $this->assertEquals(array('.', '..', 'foo.txt'), scandir('oc:///')); file_put_contents('oc:///bar.txt', 'qwerty'); $this->assertEquals('qwerty', $storage->file_get_contents('bar.txt')); $this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///')); $this->assertEquals('qwerty', file_get_contents('oc:///bar.txt')); $fh = fopen('oc:///bar.txt', 'rb'); $this->assertSame(0, ftell($fh)); $content = fread($fh, 4); $this->assertSame(4, ftell($fh)); $this->assertSame('qwer', $content); $content = fread($fh, 1); $this->assertSame(5, ftell($fh)); $this->assertSame(0, fseek($fh, 0)); $this->assertSame(0, ftell($fh)); unlink('oc:///foo.txt'); $this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///')); \OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::mount($originalStorage, array(), '/'); }
protected function setUp() { parent::setUp(); //clear all proxies and hooks so we can do clean testing \OC_FileProxy::clearProxies(); \OC_Hook::clear('OC_Filesystem'); //disabled atm //enable only the encryption hook if needed //if(OC_App::isEnabled('files_encryption')) { // OC_FileProxy::register(new OC_FileProxy_Encryption()); //} //set up temporary storage $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); \OC_Config::setValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $rootView = new \OC\Files\View(''); $rootView->mkdir('/test'); $this->instance = new \OC\Cache\UserCache(); }
protected function setUp() { parent::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(); $this->originalStorage = Filesystem::getStorage('/'); Filesystem::tearDown(); if (!self::$user) { self::$user = $this->getUniqueID(); } \OC_User::createUser(self::$user, 'password'); \OC_User::setUserId(self::$user); Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); \OC_Hook::clear('OC_Filesystem'); }
protected function setUp() { parent::setUp(); //clear all proxies and hooks so we can do clean testing \OC_Hook::clear('OC_Filesystem'); //set up temporary storage $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $config = \OC::$server->getConfig(); $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); $config->setSystemValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \Test\Util\User\Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/test'); $this->instance = new \OC\Cache\File(); // forces creation of cache folder for subsequent tests $this->instance->set('hack', 'hack'); }
protected function setUp() { parent::setUp(); $this->originalStorage = Filesystem::getStorage('/'); $this->storage = new Temporary(array()); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/'); $this->view = new View(''); $this->updater = new \OC\Files\Cache\Updater($this->view); $this->cache = $this->storage->getCache(); }
protected function setUp() { parent::setUp(); $this->user = $this->getUniqueID('user_'); \OC::$server->getUserManager()->createUser($this->user, $this->user); $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); \OC\Files\Filesystem::clearMounts(); $this->storageMock = null; }
protected function setUp() { parent::setUp(); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; }
protected function setUp() { parent::setUp(); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // create a new user with his own filesystem view // this gets called by each test in this test class $this->user = $this->getUniqueID(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . $this->user); $this->rootView->mkdir('/' . $this->user . '/files'); }
protected function setUp() { parent::setUp(); \OC_Hook::clear(); \OCA\Files_Trashbin\Trashbin::registerHooks(); $this->user = $this->getUniqueId('user'); \OC::$server->getUserManager()->createUser($this->user, $this->user); // this will setup the FS $this->loginAsUser($this->user); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OCA\Files_Trashbin\Storage::setupStorage(); $this->rootView = new \OC\Files\View('/'); $this->userView = new \OC\Files\View('/' . $this->user . '/files/'); $this->userView->file_put_contents('test.txt', 'foo'); }
protected function setUp() { parent::setUp(); \OC_Hook::clear('OC_Filesystem', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup'); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); \OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); $this->datadir = \OC_Config::getValue('datadirectory'); $this->tmpDir = \OC_Helper::tmpFolder(); \OC_Config::setValue('datadirectory', $this->tmpDir); $this->uid = \OC_User::getUser(); \OC_User::setUserId(null); $this->userBackend = new \OC_User_Dummy(); \OC_User::useBackend($this->userBackend); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC_Util::tearDownFS(); }
protected function setUp() { parent::setUp(); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // mock OC_L10n 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'); $l10nMock = $this->getMock('\\OC_L10N', array('t'), array(), '', false); $l10nMock->expects($this->any())->method('t')->will($this->returnArgument(0)); $viewMock = $this->getMock('\\OC\\Files\\View', array('rename', 'normalizePath', 'getFileInfo', 'file_exists'), array(), '', false); $viewMock->expects($this->any())->method('normalizePath')->will($this->returnArgument(0)); $viewMock->expects($this->any())->method('rename')->will($this->returnValue(true)); $this->viewMock = $viewMock; $this->files = new \OCA\Files\App($viewMock, $l10nMock); }
protected function setUp() { parent::setUp(); // FIXME: use proper tearDown with $this->loginAsUser() and $this->logout() // (would currently break the tests for some reason) $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); // create a new user with his own filesystem view // this gets called by each test in this test class $backend = new \OC_User_Dummy(); \OC_User::useBackend($backend); $backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1); $user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1); \OC::$server->getUserSession()->setUser($user); \OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files'); \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1); $this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files'); }
protected function setUp() { parent::setUp(); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::init('', ''); \OC\Files\Filesystem::clearMounts(); $manager = \OC\Files\Filesystem::getMountManager(); \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook'); \OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook'); \OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook'); \OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook'); $user = new User($this->getUniqueID('user'), new \OC_User_Dummy()); \OC_User::setUserId($user->getUID()); $this->view = new View(); $this->root = new Root($manager, $this->view, $user); $storage = new Temporary(array()); $subStorage = new Temporary(array()); $this->storages[] = $storage; $this->storages[] = $subStorage; $this->root->mount($storage, '/'); $this->root->mount($subStorage, '/substorage/'); }
$eventSource = new OC_EventSource(); ScanListener::$eventSource = $eventSource; ScanListener::$view = \OC\Files\Filesystem::getView(); OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_folder', 'ScanListener', 'folder'); OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_file', 'ScanListener', 'file'); foreach ($users as $user) { $eventSource->send('user', $user); OC_Util::tearDownFS(); OC_Util::setupFS($user); $absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir); $mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath); $mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath); $mountPoints = array_reverse($mountPoints); //start with the mount point of $dir foreach ($mountPoints as $mountPoint) { $storage = \OC\Files\Filesystem::getStorage($mountPoint); if ($storage) { ScanListener::$mountPoints[$storage->getId()] = $mountPoint; $scanner = $storage->getScanner(); if ($force) { $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG); } else { $scanner->backgroundScan(); } } } } $eventSource->send('done', ScanListener::$fileCount); $eventSource->close(); class ScanListener {
public function formatItems($items, $format, $parameters = null) { if ($format == self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call return array('parent' => $items[key($items)]['parent'], 'path' => $items[key($items)]['path'], 'storage' => $items[key($items)]['storage'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner']); } else { if ($format == self::FORMAT_GET_FOLDER_CONTENTS) { $files = array(); foreach ($items as $item) { $file = array(); $file['fileid'] = $item['file_source']; $file['storage'] = $item['storage']; $file['path'] = $item['file_target']; $file['parent'] = $item['file_parent']; $file['name'] = basename($item['file_target']); $file['mimetype'] = $item['mimetype']; $file['mimepart'] = $item['mimepart']; $file['mtime'] = $item['mtime']; $file['encrypted'] = $item['encrypted']; $file['etag'] = $item['etag']; $file['uid_owner'] = $item['uid_owner']; $file['displayname_owner'] = $item['displayname_owner']; $storage = \OC\Files\Filesystem::getStorage('/'); $cache = $storage->getCache(); if ($item['encrypted'] or $item['unencrypted_size'] > 0 and $cache->getMimetype($item['mimetype']) === 'httpd/unix-directory') { $file['size'] = $item['unencrypted_size']; $file['encrypted_size'] = $item['size']; } else { $file['size'] = $item['size']; } $files[] = $file; } return $files; } else { if ($format == self::FORMAT_OPENDIR) { $files = array(); foreach ($items as $item) { $files[] = basename($item['file_target']); } return $files; } else { if ($format == self::FORMAT_GET_ALL) { $ids = array(); foreach ($items as $item) { $ids[] = $item['file_source']; } return $ids; } else { if ($format === self::FORMAT_PERMISSIONS) { $filePermissions = array(); foreach ($items as $item) { $filePermissions[$item['file_source']] = $item['permissions']; } return $filePermissions; } else { if ($format === self::FORMAT_TARGET_NAMES) { $targets = array(); foreach ($items as $item) { $targets[] = $item['file_target']; } return $targets; } } } } } } return array(); }
/** * get the filesystem info * * @param string $path * @param boolean|string $includeMountPoints true to add mountpoint sizes, * 'ext' to add only ext storage mount point sizes. Defaults to true. * defaults to true * @return \OC\Files\FileInfo|false */ public function getFileInfo($path, $includeMountPoints = true) { $this->assertPathLength($path); $data = array(); if (!Filesystem::isValidPath($path)) { return $data; } if (Cache\Scanner::isPartialFile($path)) { return $this->getPartFileInfo($path); } $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); $mount = Filesystem::getMountManager()->find($path); $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($path); $data = null; if ($storage) { $cache = $storage->getCache($internalPath); $data = $cache->get($internalPath); $watcher = $storage->getWatcher($internalPath); // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data if (!$data) { if (!$storage->file_exists($internalPath)) { return false; } $scanner = $storage->getScanner($internalPath); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $data = $cache->get($internalPath); } else { if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->checkUpdate($internalPath, $data)) { $this->updater->propagate($path); $data = $cache->get($internalPath); } } if ($data and isset($data['fileid'])) { // upgrades from oc6 or lower might not have the permissions set in the file cache if ($data['permissions'] === 0) { $data['permissions'] = $storage->getPermissions($data['path']); $cache->update($data['fileid'], array('permissions' => $data['permissions'])); } if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') { //add the sizes of other mount points to the folder $extOnly = $includeMountPoints === 'ext'; $mountPoints = Filesystem::getMountPoints($path); foreach ($mountPoints as $mountPoint) { $subStorage = Filesystem::getStorage($mountPoint); if ($subStorage) { // exclude shared storage ? if ($extOnly && $subStorage instanceof \OC\Files\Storage\Shared) { continue; } $subCache = $subStorage->getCache(''); $rootEntry = $subCache->get(''); $data['size'] += isset($rootEntry['size']) ? $rootEntry['size'] : 0; } } } } } if (!$data) { return false; } if ($mount instanceof MoveableMount && $internalPath === '') { $data['permissions'] |= \OCP\Constants::PERMISSION_DELETE; } return new FileInfo($path, $storage, $internalPath, $data, $mount); }
/** * get the list of all unindexed files for the user * * @return array */ public function getUnindexed() { $files = array(); //TODO use server api for mounts & root $absoluteRoot = Filesystem::getView()->getAbsolutePath('/'); $mounts = Filesystem::getMountPoints($absoluteRoot); $mount = Filesystem::getMountPoint($absoluteRoot); if (!in_array($mount, $mounts)) { $mounts[] = $mount; } $query = $this->db->prepareQuery(' SELECT `*PREFIX*filecache`.`fileid` FROM `*PREFIX*filecache` LEFT JOIN `' . $this->tableName . '` ON `*PREFIX*filecache`.`fileid` = `' . $this->tableName . '`.`fileid` WHERE `storage` = ? AND ( `status` IS NULL OR `status` = ? ) AND `path` LIKE \'files/%\' '); foreach ($mounts as $mount) { if (is_string($mount)) { $storage = Filesystem::getStorage($mount); } else { if ($mount instanceof Mount) { $storage = $mount->getStorage(); } else { $storage = null; $this->logger->debug('expected string or instance of \\OC\\Files\\Mount\\Mount got ' . json_encode($mount)); } } //only index local files for now if ($storage->isLocal()) { $cache = $storage->getCache(); $numericId = $cache->getNumericStorageId(); $result = $query->execute(array($numericId, Status::STATUS_NEW)); while ($row = $result->fetchRow()) { $files[] = $row['fileid']; } } } return $files; }
/** * get the list of all unindexed files for the user * * @return array */ public static function getUnindexed() { $files = array(); $absoluteRoot = Filesystem::getView()->getAbsolutePath('/'); $mounts = Filesystem::getMountPoints($absoluteRoot); $mount = Filesystem::getMountPoint($absoluteRoot); if (!in_array($mount, $mounts)) { $mounts[] = $mount; } $query = \OC_DB::prepare(' SELECT `*PREFIX*filecache`.`fileid` FROM `*PREFIX*filecache` LEFT JOIN `*PREFIX*lucene_status` ON `*PREFIX*filecache`.`fileid` = `*PREFIX*lucene_status`.`fileid` WHERE `storage` = ? AND `status` IS NULL OR `status` = ? '); foreach ($mounts as $mount) { if (is_string($mount)) { $storage = Filesystem::getStorage($mount); } else { if ($mount instanceof \OC\Files\Mount\Mount) { $storage = $mount->getStorage(); } else { $storage = null; Util::writeLog('search_lucene', 'expected string or instance of \\OC\\Files\\Mount\\Mount got ' . json_encode($mount), Util::DEBUG); } } //only index local files for now if ($storage instanceof \OC\Files\Storage\Local) { $cache = $storage->getCache(); $numericId = $cache->getNumericStorageId(); $result = $query->execute(array($numericId, 'N')); if (\OC_DB::isError($result)) { Util::writeLog('search_lucene', 'failed to find unindexed files: ' . \OC_DB::getErrorMessage($result), Util::WARN); return false; } while ($row = $result->fetchRow()) { $files[] = $row['fileid']; } } } return $files; }
/** * Initialize system and personal mount points for a user * * @param string $user * @throws \OC\User\NoUserException if the user is not available */ public static function initMountPoints($user = '') { if ($user == '') { $user = \OC_User::getUser(); } if ($user === null || $user === false || $user === '') { throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); } if (isset(self::$usersSetup[$user])) { return; } $root = \OC_User::getHome($user); $userManager = \OC::$server->getUserManager(); $userObject = $userManager->get($user); if (is_null($userObject)) { \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } self::$usersSetup[$user] = true; $homeStorage = \OC::$server->getConfig()->getSystemValue('objectstore'); if (!empty($homeStorage)) { // sanity checks if (empty($homeStorage['class'])) { \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); } if (!isset($homeStorage['arguments'])) { $homeStorage['arguments'] = array(); } // instantiate object store implementation $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']); // mount with home object store implementation $homeStorage['class'] = '\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage'; } else { $homeStorage = array('class' => '\\OC\\Files\\Storage\\Home', 'arguments' => array()); } $homeStorage['arguments']['user'] = $userObject; // check for legacy home id (<= 5.0.12) if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { $homeStorage['arguments']['legacy'] = true; } $mount = new MountPoint($homeStorage['class'], '/' . $user, $homeStorage['arguments'], self::getLoader()); self::getMountManager()->addMount($mount); $home = \OC\Files\Filesystem::getStorage($user); // Chance to mount for other storages /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ $mountConfigManager = \OC::$server->getMountProviderCollection(); if ($userObject) { $mounts = $mountConfigManager->getMountsForUser($userObject); array_walk($mounts, array(self::$mounts, 'addMount')); $mounts[] = $mount; $mountConfigManager->registerMounts($userObject, $mounts); } self::listenForNewMountProviders($mountConfigManager, $userManager); \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root)); }
protected function setUp() { parent::setUp(); $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); }
/** * Initialize system and personal mount points for a user * * @param string $user */ public static function initMountPoints($user = '') { if ($user == '') { $user = \OC_User::getUser(); } if (isset(self::$usersSetup[$user])) { return; } self::$usersSetup[$user] = true; $root = \OC_User::getHome($user); $userObject = \OC_User::getManager()->get($user); if (!is_null($userObject)) { $homeStorage = \OC_Config::getValue('objectstore'); if (!empty($homeStorage)) { // sanity checks if (empty($homeStorage['class'])) { \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); } if (!isset($homeStorage['arguments'])) { $homeStorage['arguments'] = array(); } // instantiate object store implementation $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']); // mount with home object store implementation $homeStorage['class'] = '\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage'; } else { $homeStorage = array('class' => '\\OC\\Files\\Storage\\Home', 'arguments' => array()); } $homeStorage['arguments']['user'] = $userObject; // check for legacy home id (<= 5.0.12) if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { $homeStorage['arguments']['legacy'] = true; } self::mount($homeStorage['class'], $homeStorage['arguments'], $user); $home = \OC\Files\Filesystem::getStorage($user); } else { self::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $root), $user); } self::mountCacheDir($user); // Chance to mount for other storages if ($userObject) { $mountConfigManager = \OC::$server->getMountProviderCollection(); $mounts = $mountConfigManager->getMountsForUser($userObject); array_walk($mounts, array(self::$mounts, 'addMount')); } \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root)); }
/** * Tests that the home storage is used in legacy mode * for the user's mount point */ public function testLegacyHomeMount() { if (getenv('RUN_OBJECTSTORE_TESTS')) { $this->markTestSkipped('legacy storage unrelated to objectstore environments'); } $datadir = \OC::$server->getConfig()->getSystemValue("datadirectory", \OC::$SERVERROOT . "/data"); $userId = $this->getUniqueID('user_'); // insert storage into DB by constructing it // to make initMountsPoint find its existence $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/')); // this will trigger the insert $cache = $localStorage->getCache(); \OC::$server->getUserManager()->createUser($userId, $userId); \OC\Files\Filesystem::initMountPoints($userId); $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); $this->assertTrue($homeMount->instanceOfStorage('\\OC\\Files\\Storage\\Home')); $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); $user = \OC::$server->getUserManager()->get($userId); if ($user !== null) { $user->delete(); } // delete storage entry $cache->clear(); }
/** * Tests that the home storage is used in legacy mode * for the user's mount point */ public function testLegacyHomeMount() { $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); $userId = $this->getUniqueID('user_'); // insert storage into DB by constructing it // to make initMountsPoint find its existence $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/')); // this will trigger the insert $cache = $localStorage->getCache(); \OC_User::createUser($userId, $userId); \OC\Files\Filesystem::initMountPoints($userId); $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); $this->assertTrue($homeMount->instanceOfStorage('\\OC\\Files\\Storage\\Home')); $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); \OC_User::deleteUser($userId); // delete storage entry $cache->clear(); }
/** * @param string $query * @param string $method * @return FileInfo[] */ private function searchCommon($query, $method) { $files = array(); $rootLength = strlen($this->fakeRoot); $mountPoint = Filesystem::getMountPoint($this->fakeRoot); $storage = Filesystem::getStorage($mountPoint); if ($storage) { $cache = $storage->getCache(''); $results = $cache->{$method}($query); foreach ($results as $result) { if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') { $internalPath = $result['path']; $path = $mountPoint . $result['path']; $result['path'] = substr($mountPoint . $result['path'], $rootLength); $files[] = new FileInfo($path, $storage, $internalPath, $result); } } $mountPoints = Filesystem::getMountPoints($this->fakeRoot); foreach ($mountPoints as $mountPoint) { $storage = Filesystem::getStorage($mountPoint); if ($storage) { $cache = $storage->getCache(''); $relativeMountPoint = substr($mountPoint, $rootLength); $results = $cache->{$method}($query); if ($results) { foreach ($results as $result) { $internalPath = $result['path']; $result['path'] = rtrim($relativeMountPoint . $result['path'], '/'); $path = rtrim($mountPoint . $internalPath, '/'); $files[] = new FileInfo($path, $storage, $internalPath, $result); } } } } } return $files; }
/** * Initialize system and personal mount points for a user * * @param string $user */ public static function initMountPoints($user = '') { if ($user == '') { $user = \OC_User::getUser(); } $parser = new \OC\ArrayParser(); $root = \OC_User::getHome($user); $userObject = \OC_User::getManager()->get($user); if (is_null($userObject)) { \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } $homeStorage = \OC_Config::getValue('objectstore'); if (!empty($homeStorage)) { // sanity checks if (empty($homeStorage['class'])) { \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); } if (!isset($homeStorage['arguments'])) { $homeStorage['arguments'] = array(); } // instantiate object store implementation $homeStorage['arguments']['objectstore'] = new $homeStorage['class']($homeStorage['arguments']); // mount with home object store implementation $homeStorage['class'] = '\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage'; } else { $homeStorage = array('class' => '\\OC\\Files\\Storage\\Home', 'arguments' => array()); } $homeStorage['arguments']['user'] = $userObject; // check for legacy home id (<= 5.0.12) if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { $homeStorage['arguments']['legacy'] = true; } self::mount($homeStorage['class'], $homeStorage['arguments'], $user); $home = \OC\Files\Filesystem::getStorage($user); self::mountCacheDir($user); // Chance to mount for other storages \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root)); }
/** * Initialize system and personal mount points for a user * * @param string $user * @throws \OC\User\NoUserException if the user is not available */ public static function initMountPoints($user = '') { if ($user == '') { $user = \OC_User::getUser(); } if ($user === null || $user === false || $user === '') { throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); } if (isset(self::$usersSetup[$user])) { return; } $userManager = \OC::$server->getUserManager(); $userObject = $userManager->get($user); if (is_null($userObject)) { \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } self::$usersSetup[$user] = true; /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ $mountConfigManager = \OC::$server->getMountProviderCollection(); // home mounts are handled seperate since we need to ensure this is mounted before we call the other mount providers $homeMount = $mountConfigManager->getHomeMountForUser($userObject); self::getMountManager()->addMount($homeMount); \OC\Files\Filesystem::getStorage($user); // Chance to mount for other storages if ($userObject) { $mounts = $mountConfigManager->getMountsForUser($userObject); array_walk($mounts, array(self::$mounts, 'addMount')); $mounts[] = $homeMount; $mountConfigManager->registerMounts($userObject, $mounts); } self::listenForNewMountProviders($mountConfigManager, $userManager); \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user)); }