diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php
index 7daae26d1db8..fc06fe6eacb3 100644
--- a/apps/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -24,7 +24,7 @@
foreach ($users as $user) {
$eventSource->send('user', $user);
- $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getUserFolder($user));
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file'));
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', array($listener, 'folder'));
if ($force) {
diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php
index 87f799a01871..d3b925f01316 100644
--- a/apps/files/command/scan.php
+++ b/apps/files/command/scan.php
@@ -58,7 +58,7 @@ protected function configure() {
}
protected function scanFiles($user, $path, $quiet, OutputInterface $output) {
- $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getUserFolder($user));
if (!$quiet) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("Scanning file $path");
diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php
index 488c741d3f67..f8b9ac3eb428 100644
--- a/apps/files/tests/ajax_rename.php
+++ b/apps/files/tests/ajax_rename.php
@@ -48,7 +48,7 @@ protected function setUp() {
\OC_User::createUser(self::$user, 'password');
\OC_User::setUserId(self::$user);
- \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
+ \OC_Util::setupFS(self::$user);
$l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false);
$l10nMock->expects($this->any())
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index ae9f0af4890b..5743feae144d 100644
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -73,6 +73,10 @@ public static function registerFilesystemHooks() {
\OCP\Util::connectHook('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', 'OCA\Files_Encryption\Hooks', 'postPasswordReset');
\OCP\Util::connectHook('OC_Filesystem', 'post_umount', 'OCA\Files_Encryption\Hooks', 'postUnmount');
\OCP\Util::connectHook('OC_Filesystem', 'umount', 'OCA\Files_Encryption\Hooks', 'preUnmount');
+
+ $factory = \OC::$server->getFilesystemFactory();
+ $factory->listen('\OC\Files', 'preCopySkeleton', array('OCA\Encryption\Hooks', 'preCopySkeleton'));
+ $factory->listen('\OC\Files', 'postCopySkeleton', array('OCA\Encryption\Hooks', 'postCopySkeleton'));
}
/**
diff --git a/apps/files_encryption/lib/hooks.php b/apps/files_encryption/lib/hooks.php
index 1ffcee5e74ad..3b95a0a97314 100644
--- a/apps/files_encryption/lib/hooks.php
+++ b/apps/files_encryption/lib/hooks.php
@@ -37,6 +37,8 @@ class Hooks {
// file for which we want to delete the keys after the delete operation was successful
private static $unmountedFiles = array();
+ private static $proxyStatus;
+
/**
* Startup encryption backend upon user login
* @note This method should never be called for users using client side encryption
@@ -222,7 +224,7 @@ public static function setPassphrase($params) {
$newUserPassword = $params['password'];
// make sure that the users home is mounted
- \OC\Files\Filesystem::initMountPoints($user);
+ \OC::$server->setupFilesystem($user);
$keypair = Crypt::createKeypair();
@@ -625,4 +627,15 @@ public static function postUnmount($params) {
}
}
+ /**
+ * disable encryption while copying the skeleton
+ */
+ public static function preCopySkeleton(){
+ self::$proxyStatus = \OC_FileProxy::$enabled;
+ self::$proxyStatus = false;
+ }
+
+ public static function postCopySkeleton() {
+ \OC_FileProxy::$enabled = self::$proxyStatus;
+ }
}
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 14d0a0bc4b9c..10a70d6f6bf9 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -136,7 +136,7 @@ public function __construct($view, $userId, $client = false) {
$this->privateKeyPath =
$this->encryptionDir . '/' . $this->userId . '.privateKey'; // e.g. data/admin/admin.privateKey
// make sure that the owners home is mounted
- \OC\Files\Filesystem::initMountPoints($userId);
+ \OC::$server->setupFilesystem($userId);
if (Helper::isPublicAccess()) {
$this->keyId = $this->publicShareKeyId;
@@ -1276,7 +1276,7 @@ public function getUidAndFilename($path) {
}
// NOTE: Bah, this dependency should be elsewhere
- \OC\Files\Filesystem::initMountPoints($fileOwnerUid);
+ \OC::$server->setupFilesystem($fileOwnerUid);
// If the file owner is the currently logged in user
if ($fileOwnerUid === $this->userId) {
diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php
index 3fedd1b933f1..618a76276d32 100644
--- a/apps/files_sharing/ajax/publicpreview.php
+++ b/apps/files_sharing/ajax/publicpreview.php
@@ -41,7 +41,6 @@
OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
\OC_Util::setupFS($userId);
-\OC\Files\Filesystem::initMountPoints($userId);
$view = new \OC\Files\View('/' . $userId . '/files');
$pathId = $linkedItem['file_source'];
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index b71dfb44ab01..0248d253964e 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -53,7 +53,7 @@ private function getSourceCache($target) {
}
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
if (isset($source['path']) && isset($source['fileOwner'])) {
- \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
+ \OC::$server->setupFilesystem($source['fileOwner']);
$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
if (is_array($mounts) and !empty($mounts)) {
$fullPath = $mounts[0]->getMountPoint() . $source['path'];
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index 8fabd8d42d70..d77437dcebb5 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -141,7 +141,7 @@ public static function authenticate($linkItem, $password = null) {
public static function getSharesFromItem($target) {
$result = array();
$owner = \OC\Files\Filesystem::getOwner($target);
- \OC\Files\Filesystem::initMountPoints($owner);
+ \OC::$server->setupFilesystem($owner);
$info = \OC\Files\Filesystem::getFileInfo($target);
$ownerView = new \OC\Files\View('/'.$owner.'/files');
if ( $owner != \OCP\User::getUser() ) {
@@ -179,7 +179,7 @@ public static function getSharesFromItem($target) {
public static function getUidAndFilename($filename) {
$uid = \OC\Files\Filesystem::getOwner($filename);
- \OC\Files\Filesystem::initMountPoints($uid);
+ \OC::$server->setupFilesystem($uid);
if ( $uid != \OCP\User::getUser() ) {
$info = \OC\Files\Filesystem::getFileInfo($filename);
$ownerView = new \OC\Files\View('/'.$uid.'/files');
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index dae859781e2a..f98e4d4d607f 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -74,7 +74,7 @@ public function generateTarget($filePath, $shareWith, $exclude = null) {
return $target;
}
- \OC\Files\Filesystem::initMountPoints($shareWith);
+ \OC::$server->setupFilesystem($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files');
if (!$view->is_dir($shareFolder)) {
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index ccfbebddb294..2960fc6c44bf 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -86,7 +86,7 @@ public function getSourcePath($target) {
$source = $this->getFile($target);
if ($source) {
if (!isset($source['fullPath'])) {
- \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
+ \OC::$server->setupFilesystem($source['fileOwner']);
$mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
if (is_array($mount) && !empty($mount)) {
$this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint() . $source['path'];
diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php
index 9d8ae7cbb4f5..41da4b38c013 100644
--- a/apps/files_sharing/lib/updater.php
+++ b/apps/files_sharing/lib/updater.php
@@ -35,7 +35,7 @@ static private function correctUsersFolder($user, $path) {
// $path points to the mount point which is a virtual folder, so we start with
// the parent
$path = '/files' . dirname($path);
- \OC\Files\Filesystem::initMountPoints($user);
+ \OC::$server->setupFilesystem($user);
$view = new \OC\Files\View('/' . $user);
if ($view->file_exists($path)) {
while ($path !== dirname($path)) {
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 6a7636a46f28..281f12f43db8 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -42,7 +42,7 @@ class Trashbin {
public static function getUidAndFilename($filename) {
$uid = \OC\Files\Filesystem::getOwner($filename);
- \OC\Files\Filesystem::initMountPoints($uid);
+ \OC::$server->setupFilesystem($uid);
if ($uid != \OCP\User::getUser()) {
$info = \OC\Files\Filesystem::getFileInfo($filename);
$ownerView = new \OC\Files\View('/' . $uid . '/files');
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 60a4c463fd51..aafb9321daca 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -43,7 +43,7 @@ class Storage {
public static function getUidAndFilename($filename) {
$uid = \OC\Files\Filesystem::getOwner($filename);
- \OC\Files\Filesystem::initMountPoints($uid);
+ \OC::$server->setupFilesystem($uid);
if ( $uid != \OCP\User::getUser() ) {
$info = \OC\Files\Filesystem::getFileInfo($filename);
$ownerView = new \OC\Files\View('/'.$uid.'/files');
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index cf0ffb320e2f..21ad64f8d2df 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -46,9 +46,10 @@ public static function setUpBeforeClass() {
\OCA\Files_Versions\Hooks::connectHooks();
\OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
- // create test user
- self::loginHelper(self::TEST_VERSIONS_USER2, true);
- self::loginHelper(self::TEST_VERSIONS_USER, true);
+ $backend = new OC_User_Dummy();
+ \OC_User::useBackend($backend);
+ $backend->createUser(self::TEST_VERSIONS_USER, self::TEST_VERSIONS_USER);
+ $backend->createUser(self::TEST_VERSIONS_USER2, self::TEST_VERSIONS_USER2);
}
public static function tearDownAfterClass() {
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php
index 6fa7686ea96e..0bdf462fbf8b 100644
--- a/lib/private/cache/file.php
+++ b/lib/private/cache/file.php
@@ -27,7 +27,7 @@ protected function getStorage() {
if (\OC_User::isLoggedIn()) {
$rootView = new View();
$user = \OC::$server->getUserSession()->getUser();
- Filesystem::initMountPoints($user->getUID());
+ \OC::$server->setupFilesystem(\OC_User::getUser());
if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
$rootView->mkdir('/' . $user->getUID() . '/cache');
}
diff --git a/lib/private/files/factory.php b/lib/private/files/factory.php
new file mode 100644
index 000000000000..06a9e569b709
--- /dev/null
+++ b/lib/private/files/factory.php
@@ -0,0 +1,218 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files;
+
+use OC\Files\Mount\Manager;
+use OC\Files\Node\Root;
+use OC\Files\Storage\StorageFactory;
+use OC\Files\Storage\Wrapper\Quota;
+use OC\Hooks\BasicEmitter;
+use OCP\Files\Config\IMountProviderCollection;
+use OCP\Files\FileInfo;
+use OCP\IUser;
+
+class Factory extends BasicEmitter {
+ /**
+ * @var \OCP\IConfig
+ */
+ protected $config;
+
+ /**
+ * @var \OCP\Files\Config\IMountProviderCollection
+ */
+ protected $mountProvider;
+
+ /**
+ * @var \OC\Files\Node\Root
+ */
+ protected $root;
+
+ /**
+ * @var \OCP\Files\Folder[]
+ */
+ protected $userFolders = array();
+
+ /**
+ * @var \OC\Files\Storage\StorageFactory
+ */
+ private $storageFactory;
+
+ /**
+ * @param \OCP\IConfig $config
+ * @param \OCP\Files\Config\IMountProviderCollection $mountProvider
+ * @param \OC\Files\Storage\StorageFactory $storageFactory
+ */
+ public function __construct($config, IMountProviderCollection $mountProvider, StorageFactory $storageFactory) {
+ $this->config = $config;
+ $this->mountProvider = $mountProvider;
+ $this->storageFactory = $storageFactory;
+ }
+
+ /**
+ * Mount the data dir as root storage
+ *
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OC\Files\Storage\StorageFactory $storageLoader
+ */
+ protected function mountRoot(Manager $mountManager, StorageFactory $storageLoader) {
+ // mount local file backend as root
+ $configDataDirectory = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . "/data");
+ //first set up the local "root" storage
+ $mount = new Mount\MountPoint('\OC\Files\Storage\Local', '/', array('datadir' => $configDataDirectory), $storageLoader);
+ $mountManager->addMount($mount);
+ }
+
+ /**
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OC\Files\Storage\StorageFactory $storageLoader
+ * @param \OCP\IUser $user
+ */
+ protected function mountUserFolder($mountManager, $storageLoader, $user) {
+ // check for legacy home id (<= 5.0.12)
+ $legacy = \OC\Files\Cache\Storage::exists('local::' . $user->getHome() . '/');
+ $mount = new Mount\MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), array(
+ 'datadir' => $user->getHome(),
+ 'user' => $user,
+ 'legacy' => $legacy
+ ), $storageLoader);
+ $mountManager->addMount($mount);
+ }
+
+ /**
+ * setup any mounts provided by apps
+ *
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OCP\IUser $user
+ */
+ protected function setupFromProviders(Manager $mountManager, IUser $user) {
+ // Chance to mount for other storages
+ $mounts = $this->mountProvider->getMountsForUser($user);
+ array_walk($mounts, array($mountManager, 'addMount'));
+ }
+
+ /**
+ * Mount the cache storage if configured and create the cache dir if needed
+ *
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OC\Files\Storage\StorageFactory $storageLoader
+ * @param \OCP\IUser $user
+ */
+ protected function setupCacheDir($mountManager, $storageLoader, $user) {
+ $cacheBaseDir = $this->config->getSystemValue('cache_path', '');
+ if ($cacheBaseDir === '') {
+ // use local cache dir relative to the user's home
+ $mount = $mountManager->find('/' . $user->getUID());
+ $userStorage = $mount->getStorage();
+ if (!$userStorage->file_exists('cache')) {
+ $userStorage->mkdir('cache');
+ }
+ } else {
+ $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID();
+ if (!file_exists($cacheDir)) {
+ mkdir($cacheDir, 0770, true);
+ }
+ $mount = new Mount\MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', array('datadir' => $cacheDir), $storageLoader);
+ $mountManager->addMount($mount);
+ }
+ }
+
+ /**
+ * @param \OCP\IUser $user
+ */
+ protected function copySkeleton($user) {
+ $root = $this->getRoot();
+ $path = '/' . $user->getUID() . '/files';
+ if (!$root->nodeExists($path)) {
+ $this->emit('\OC\Files', 'preCopySkeleton', array($user));
+ $userDirectory = $root->newFolder($path);
+ $skeletonDirectory = $this->config->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
+ if (!empty($skeletonDirectory)) {
+ \OC_Util::copyr($skeletonDirectory, $userDirectory);
+ }
+ $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
+ $this->emit('\OC\Files', 'postCopySkeleton', array($user));
+ }
+ }
+
+ /**
+ * Create the root filesystem
+ *
+ * @return \OC\Files\Node\Root
+ */
+ public function getRoot() {
+ if ($this->root) {
+ return $this->root;
+ }
+ $mountManager = new Manager();
+ \OC::$server->getEventLogger()->start('setup_fs_root', 'Setup filesystem root');
+ $this->storageFactory->addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
+ /**
+ * @var \OCP\Files\IHomeStorage $storage
+ */
+ if (is_object($storage->getUser())) {
+ $user = $storage->getUser()->getUID();
+ $quota = \OC_Util::getUserQuota($user);
+ if ($quota !== FileInfo::SPACE_UNLIMITED) {
+ return new Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
+ }
+ }
+ }
+ return $storage;
+ });
+
+ $this->mountRoot($mountManager, $this->storageFactory);
+ \OC::$server->getEventLogger()->end('setup_fs_root');
+ $this->root = new Root($mountManager, $this->storageFactory, new View(''));
+ return $this->root;
+ }
+
+ /**
+ * Mount the storages for a user
+ *
+ * @param \OCP\IUser $user
+ * @return \OCP\Files\Folder
+ */
+ public function getUserFolder($user) {
+ if (isset($this->userFolders[$user->getUID()])) {
+ return $this->userFolders[$user->getUID()];
+ }
+ $root = $this->getRoot();
+ $mountManager = $root->getMountManager();
+ $storageLoader = $root->getStorageLoader();
+ if (is_null($mountManager->getMount('/' . $user->getUID()))) {
+ \OC::$server->getEventLogger()->start('setup_fs_' . $user->getUID(), 'Setup filesystem for ' . $user->getUID());
+ $this->mountUserFolder($mountManager, $storageLoader, $user);
+ $this->setupFromProviders($mountManager, $user);
+ $this->setupCacheDir($mountManager, $storageLoader, $user);
+ $this->copySkeleton($user);
+ \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user->getUID(), 'user_dir' => $user->getHome()));
+
+ \OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user->getUID(), 'user_dir' => $user->getHome() . '/files'));
+ \OC::$server->getEventLogger()->end('setup_fs_' . $user->getUID());
+ }
+ $this->userFolders[$user->getUID()] = $root->get('/' . $user->getUID());
+ return $this->userFolders[$user->getUID()];
+ }
+
+ /**
+ * Clear all mounts in the filesystem
+ *
+ * @param bool $preserveRoot whether or not to keep the root storage
+ */
+ public function clear($preserveRoot = false) {
+ if ($this->root) {
+ $this->userFolders = array();
+ $this->root->getMountManager()->clear($preserveRoot);
+ }
+ }
+}
diff --git a/lib/private/files/fileinfomanager.php b/lib/private/files/fileinfomanager.php
new file mode 100644
index 000000000000..923cf7139178
--- /dev/null
+++ b/lib/private/files/fileinfomanager.php
@@ -0,0 +1,37 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files;
+
+class FileInfoManager {
+ /**
+ * @var \OC\Files\FileInfo[]
+ */
+ protected $entries = array();
+
+ /**
+ * @var \OC\Files\View
+ */
+ protected $view;
+
+ public function __construct(View $view) {
+ $this->view = $view;
+ }
+
+ public function register(FileInfo $entry) {
+ $this->entries[$entry->getPath()] = $entry;
+ }
+
+ public function getFileInfo($path) {
+ if (isset($this->entries[$path])) {
+ return $this->entries[$path];
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index c3a062cd2d6f..6005f139228a 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -30,22 +30,18 @@
namespace OC\Files;
-use OC\Files\Storage\StorageFactory;
-
class Filesystem {
-
/**
- * @var Mount\Manager $mounts
+ * @var \OC\Files\View $defaultInstance
*/
- private static $mounts;
+ static private $defaultInstance;
- public static $loaded = false;
/**
- * @var \OC\Files\View $defaultInstance
+ * @var \OCP\IUser
*/
- static private $defaultInstance;
+ static public $activeUser;
- static private $usersSetup = array();
+ static public $loaded;
static private $normalizedPathCache = array();
@@ -167,11 +163,7 @@ class Filesystem {
const signal_param_users = 'users';
/**
- * @var \OC\Files\Storage\StorageFactory $loader
- */
- private static $loader;
-
- /**
+ * @param string $wrapperName
* @param callable $wrapper
*/
public static function addStorageWrapper($wrapperName, $wrapper) {
@@ -188,10 +180,9 @@ public static function addStorageWrapper($wrapperName, $wrapper) {
* @return \OCP\Files\Storage\IStorageFactory
*/
public static function getLoader() {
- if (!self::$loader) {
- self::$loader = new StorageFactory();
- }
- return self::$loader;
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ return $root->getStorageLoader();
}
/**
@@ -200,10 +191,9 @@ public static function getLoader() {
* @return \OC\Files\Mount\Manager
*/
public static function getMountManager() {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- return self::$mounts;
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ return $root->getMountManager();
}
/**
@@ -216,10 +206,9 @@ public static function getMountManager() {
* @return string
*/
static public function getMountPoint($path) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- $mount = self::$mounts->find($path);
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ $mount = $root->getMount($path);
if ($mount) {
return $mount->getMountPoint();
} else {
@@ -234,11 +223,10 @@ static public function getMountPoint($path) {
* @return string[]
*/
static public function getMountPoints($path) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ $mounts = $root->getMountsIn($path);
$result = array();
- $mounts = self::$mounts->findIn($path);
foreach ($mounts as $mount) {
$result[] = $mount->getMountPoint();
}
@@ -252,10 +240,9 @@ static public function getMountPoints($path) {
* @return \OC\Files\Storage\Storage
*/
public static function getStorage($mountPoint) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- $mount = self::$mounts->find($mountPoint);
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ $mount = $root->getMount($mountPoint);
return $mount->getStorage();
}
@@ -264,10 +251,9 @@ public static function getStorage($mountPoint) {
* @return Mount\MountPoint[]
*/
public static function getMountByStorageId($id) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- return self::$mounts->findByStorageId($id);
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ return $root->getMountByStorageId($id);
}
/**
@@ -275,10 +261,9 @@ public static function getMountByStorageId($id) {
* @return Mount\MountPoint[]
*/
public static function getMountByNumericId($id) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- return self::$mounts->findByNumericId($id);
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ return $root->getMountByNumericStorageId($id);
}
/**
@@ -288,10 +273,9 @@ public static function getMountByNumericId($id) {
* @return array an array consisting of the storage and the internal path
*/
static public function resolvePath($path) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
- $mount = self::$mounts->find($path);
+ /** @var \OC\Files\Node\Root $root */
+ $root = \OC::$server->getRootFolder();
+ $mount = $root->getMount($path);
if ($mount) {
return array($mount->getStorage(), rtrim($mount->getInternalPath($path), '/'));
} else {
@@ -299,110 +283,13 @@ static public function resolvePath($path) {
}
}
- static public function init($user, $root) {
- if (self::$defaultInstance) {
- return false;
- }
- self::getLoader();
- self::$defaultInstance = new View($root);
-
- if (!self::$mounts) {
- self::$mounts = new Mount\Manager();
- }
-
- //load custom mount config
- self::initMountPoints($user);
-
- self::$loaded = true;
-
- return true;
- }
-
- static public function initMounts() {
- if (!self::$mounts) {
- self::$mounts = new Mount\Manager();
- }
- }
-
/**
* 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(
- //default home storage configuration:
- '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));
- }
-
- /**
- * Mounts the cache directory
- * @param string $user user name
- */
- private static function mountCacheDir($user) {
- $cacheBaseDir = \OC_Config::getValue('cache_path', '');
- if ($cacheBaseDir !== '') {
- $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user;
- if (!file_exists($cacheDir)) {
- mkdir($cacheDir, 0770, true);
- }
- // mount external cache dir to "/$user/cache" mount point
- self::mount('\OC\Files\Storage\Local', array('datadir' => $cacheDir), '/' . $user . '/cache');
- }
+ \OC::$server->setupFilesystem($user);
}
/**
@@ -411,6 +298,14 @@ private static function mountCacheDir($user) {
* @return View
*/
static public function getView() {
+ if (!self::$defaultInstance) {
+ $user = self::$activeUser;
+ if ($user) {
+ self::$defaultInstance = new View('/' . $user->getUID() . '/files');
+ } else {
+ self::$defaultInstance = new View();
+ }
+ }
return self::$defaultInstance;
}
@@ -418,31 +313,26 @@ static public function getView() {
* tear down the filesystem, removing all storage providers
*/
static public function tearDown() {
- self::clearMounts();
+ \OC::$server->getFilesystemFactory()->clear(true);
self::$defaultInstance = null;
}
/**
* get the relative path of the root data directory for the current user
+ *
* @return string
*
* Returns path like /admin/files
*/
static public function getRoot() {
- if (!self::$defaultInstance) {
- return null;
- }
- return self::$defaultInstance->getRoot();
+ return self::getView()->getRoot();
}
/**
* clear all mounts and storage backends
*/
public static function clearMounts() {
- if (self::$mounts) {
- self::$usersSetup = array();
- self::$mounts->clear();
- }
+ \OC::$server->getFilesystemFactory()->clear();
}
/**
@@ -453,11 +343,8 @@ public static function clearMounts() {
* @param string $mountpoint
*/
static public function mount($class, $arguments, $mountpoint) {
- if (!self::$mounts) {
- \OC_Util::setupFS();
- }
$mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader());
- self::$mounts->addMount($mount);
+ self::getMountManager()->addMount($mount);
}
/**
@@ -469,7 +356,7 @@ static public function mount($class, $arguments, $mountpoint) {
* @return string
*/
static public function getLocalFile($path) {
- return self::$defaultInstance->getLocalFile($path);
+ return self::getView()->getLocalFile($path);
}
/**
@@ -477,22 +364,7 @@ static public function getLocalFile($path) {
* @return string
*/
static public function getLocalFolder($path) {
- return self::$defaultInstance->getLocalFolder($path);
- }
-
- /**
- * return path to file which reflects one visible in browser
- *
- * @param string $path
- * @return string
- */
- static public function getLocalPath($path) {
- $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files';
- $newpath = $path;
- if (strncmp($newpath, $datadir, strlen($datadir)) == 0) {
- $newpath = substr($path, strlen($datadir));
- }
- return $newpath;
+ return self::getView()->getLocalFolder($path);
}
/**
@@ -546,6 +418,7 @@ static public function isFileBlacklisted($filename) {
/**
* check if the directory should be ignored when scanning
* NOTE: the special directories . and .. would cause never ending recursion
+ *
* @param String $dir
* @return boolean
*/
@@ -560,136 +433,136 @@ static public function isIgnoredDir($dir) {
* following functions are equivalent to their php builtin equivalents for arguments/return values.
*/
static public function mkdir($path) {
- return self::$defaultInstance->mkdir($path);
+ return self::getView()->mkdir($path);
}
static public function rmdir($path) {
- return self::$defaultInstance->rmdir($path);
+ return self::getView()->rmdir($path);
}
static public function opendir($path) {
- return self::$defaultInstance->opendir($path);
+ return self::getView()->opendir($path);
}
static public function readdir($path) {
- return self::$defaultInstance->readdir($path);
+ return self::getView()->readdir($path);
}
static public function is_dir($path) {
- return self::$defaultInstance->is_dir($path);
+ return self::getView()->is_dir($path);
}
static public function is_file($path) {
- return self::$defaultInstance->is_file($path);
+ return self::getView()->is_file($path);
}
static public function stat($path) {
- return self::$defaultInstance->stat($path);
+ return self::getView()->stat($path);
}
static public function filetype($path) {
- return self::$defaultInstance->filetype($path);
+ return self::getView()->filetype($path);
}
static public function filesize($path) {
- return self::$defaultInstance->filesize($path);
+ return self::getView()->filesize($path);
}
static public function readfile($path) {
- return self::$defaultInstance->readfile($path);
+ return self::getView()->readfile($path);
}
static public function isCreatable($path) {
- return self::$defaultInstance->isCreatable($path);
+ return self::getView()->isCreatable($path);
}
static public function isReadable($path) {
- return self::$defaultInstance->isReadable($path);
+ return self::getView()->isReadable($path);
}
static public function isUpdatable($path) {
- return self::$defaultInstance->isUpdatable($path);
+ return self::getView()->isUpdatable($path);
}
static public function isDeletable($path) {
- return self::$defaultInstance->isDeletable($path);
+ return self::getView()->isDeletable($path);
}
static public function isSharable($path) {
- return self::$defaultInstance->isSharable($path);
+ return self::getView()->isSharable($path);
}
static public function file_exists($path) {
- return self::$defaultInstance->file_exists($path);
+ return self::getView()->file_exists($path);
}
static public function filemtime($path) {
- return self::$defaultInstance->filemtime($path);
+ return self::getView()->filemtime($path);
}
static public function touch($path, $mtime = null) {
- return self::$defaultInstance->touch($path, $mtime);
+ return self::getView()->touch($path, $mtime);
}
/**
* @return string
*/
static public function file_get_contents($path) {
- return self::$defaultInstance->file_get_contents($path);
+ return self::getView()->file_get_contents($path);
}
static public function file_put_contents($path, $data) {
- return self::$defaultInstance->file_put_contents($path, $data);
+ return self::getView()->file_put_contents($path, $data);
}
static public function unlink($path) {
- return self::$defaultInstance->unlink($path);
+ return self::getView()->unlink($path);
}
static public function rename($path1, $path2) {
- return self::$defaultInstance->rename($path1, $path2);
+ return self::getView()->rename($path1, $path2);
}
static public function copy($path1, $path2) {
- return self::$defaultInstance->copy($path1, $path2);
+ return self::getView()->copy($path1, $path2);
}
static public function fopen($path, $mode) {
- return self::$defaultInstance->fopen($path, $mode);
+ return self::getView()->fopen($path, $mode);
}
/**
* @return string
*/
static public function toTmpFile($path) {
- return self::$defaultInstance->toTmpFile($path);
+ return self::getView()->toTmpFile($path);
}
static public function fromTmpFile($tmpFile, $path) {
- return self::$defaultInstance->fromTmpFile($tmpFile, $path);
+ return self::getView()->fromTmpFile($tmpFile, $path);
}
static public function getMimeType($path) {
- return self::$defaultInstance->getMimeType($path);
+ return self::getView()->getMimeType($path);
}
static public function hash($type, $path, $raw = false) {
- return self::$defaultInstance->hash($type, $path, $raw);
+ return self::getView()->hash($type, $path, $raw);
}
static public function free_space($path = '/') {
- return self::$defaultInstance->free_space($path);
+ return self::getView()->free_space($path);
}
static public function search($query) {
- return self::$defaultInstance->search($query);
+ return self::getView()->search($query);
}
/**
* @param string $query
*/
static public function searchByMime($query) {
- return self::$defaultInstance->searchByMime($query);
+ return self::getView()->searchByMime($query);
}
/**
@@ -709,11 +582,12 @@ static public function searchByTag($tag, $userId) {
* @return bool
*/
static public function hasUpdated($path, $time) {
- return self::$defaultInstance->hasUpdated($path, $time);
+ return self::getView()->hasUpdated($path, $time);
}
/**
* Fix common problems with a file path
+ *
* @param string $path
* @param bool $stripTrailingSlash
* @param bool $isAbsolutePath
@@ -792,7 +666,7 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
* @return \OC\Files\FileInfo
*/
public static function getFileInfo($path, $includeMountPoints = true) {
- return self::$defaultInstance->getFileInfo($path, $includeMountPoints);
+ return self::getView()->getFileInfo($path, $includeMountPoints);
}
/**
@@ -805,7 +679,7 @@ public static function getFileInfo($path, $includeMountPoints = true) {
* returns the fileid of the updated file
*/
public static function putFileInfo($path, $data) {
- return self::$defaultInstance->putFileInfo($path, $data);
+ return self::getView()->putFileInfo($path, $data);
}
/**
@@ -816,7 +690,7 @@ public static function putFileInfo($path, $data) {
* @return \OC\Files\FileInfo[]
*/
public static function getDirectoryContent($directory, $mimetype_filter = '') {
- return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
+ return self::getView()->getDirectoryContent($directory, $mimetype_filter);
}
/**
@@ -828,7 +702,7 @@ public static function getDirectoryContent($directory, $mimetype_filter = '') {
* @return string
*/
public static function getPath($id) {
- return self::$defaultInstance->getPath($id);
+ return self::getView()->getPath($id);
}
/**
@@ -838,7 +712,7 @@ public static function getPath($id) {
* @return string
*/
public static function getOwner($path) {
- return self::$defaultInstance->getOwner($path);
+ return self::getView()->getOwner($path);
}
/**
@@ -848,6 +722,6 @@ public static function getOwner($path) {
* @return string
*/
static public function getETag($path) {
- return self::$defaultInstance->getETag($path);
+ return self::getView()->getETag($path);
}
}
diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php
index 8472ebc976a4..76018a42f850 100644
--- a/lib/private/files/mount/manager.php
+++ b/lib/private/files/mount/manager.php
@@ -23,6 +23,14 @@ public function addMount(MountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
}
+ /**
+ * @param string $mountPoint
+ * @return Mount
+ */
+ public function getMount($mountPoint) {
+ return isset($this->mounts[$mountPoint]) ? $this->mounts[$mountPoint] : null;
+ }
+
/**
* @param string $mountPoint
*/
@@ -38,7 +46,7 @@ public function removeMount($mountPoint) {
* @param string $mountPoint
* @param string $target
*/
- public function moveMount($mountPoint, $target){
+ public function moveMount($mountPoint, $target) {
$this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]);
}
@@ -50,7 +58,6 @@ public function moveMount($mountPoint, $target){
* @return MountPoint
*/
public function find($path) {
- \OC_Util::setupFS();
$path = $this->formatPath($path);
if (isset($this->mounts[$path])) {
return $this->mounts[$path];
@@ -78,7 +85,6 @@ public function find($path) {
* @return MountPoint[]
*/
public function findIn($path) {
- \OC_Util::setupFS();
$path = $this->formatPath($path);
$result = array();
$pathLength = strlen($path);
@@ -91,8 +97,20 @@ public function findIn($path) {
return $result;
}
- public function clear() {
- $this->mounts = array();
+ /**
+ * Clear all mounts in the filesystem
+ *
+ * @param bool $preserveRoot whether or not to keep the root storage
+ */
+ public function clear($preserveRoot) {
+ if ($preserveRoot) {
+ $this->mounts = array_filter($this->mounts, function ($mount) {
+ /** @var \OC\Files\Mount\Mount $mount */
+ return $mount->getMountPoint() === '/';
+ });
+ } else {
+ $this->mounts = array();
+ }
}
/**
@@ -102,7 +120,6 @@ public function clear() {
* @return MountPoint[]
*/
public function findByStorageId($id) {
- \OC_Util::setupFS();
if (strlen($id) > 64) {
$id = md5($id);
}
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 5fd73cc5d361..58f719d1ccbb 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -255,10 +255,9 @@ public function searchByTag($tag, $userId) {
private function searchCommon($method, $args) {
$files = array();
$rootLength = strlen($this->path);
- /**
- * @var \OC\Files\Storage\Storage $storage
- */
- list($storage, $internalPath) = $this->view->resolvePath($this->path);
+ $mount = $this->root->getMount($this->path);
+ $storage = $mount->getStorage();
+ $internalPath=$mount->getInternalPath($this->path);
$internalPath = rtrim($internalPath, '/') . '/';
$internalRootLength = strlen($internalPath);
diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php
index e5b219420cd5..fe3d563f19a9 100644
--- a/lib/private/files/node/node.php
+++ b/lib/private/files/node/node.php
@@ -285,6 +285,15 @@ protected function normalizePath($path) {
return $path;
}
+ /**
+ * Get the root folder of the filesystem
+ *
+ * @return \OCP\Files\Folder
+ */
+ public function getRoot() {
+ return $this->root;
+ }
+
/**
* check if the requested path is valid
*
diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php
index 1834ef67befa..83631d012613 100644
--- a/lib/private/files/node/root.php
+++ b/lib/private/files/node/root.php
@@ -45,34 +45,39 @@ class Root extends Folder implements IRootFolder {
private $mountManager;
/**
- * @var \OC\Hooks\PublicEmitter
+ * @var \OC\Files\Storage\StorageFactory
*/
- private $emitter;
+ private $loader;
/**
- * @var \OC\User\User $user
+ * @var \OC\Hooks\PublicEmitter
*/
- private $user;
+ private $emitter;
/**
* @param \OC\Files\Mount\Manager $manager
+ * @param \OC\Files\Storage\StorageFactory $loader
* @param \OC\Files\View $view
- * @param \OC\User\User $user
*/
- public function __construct($manager, $view, $user) {
+ public function __construct($manager, $loader, $view) {
parent::__construct($this, $view, '');
+ $this->loader = $loader;
$this->mountManager = $manager;
- $this->user = $user;
$this->emitter = new PublicEmitter();
}
/**
- * Get the user for which the filesystem is setup
- *
- * @return \OC\User\User
+ * @return \OC\Files\Mount\Manager
+ */
+ public function getMountManager() {
+ return $this->mountManager;
+ }
+
+ /**
+ * @return \OC\Files\Storage\StorageFactory
*/
- public function getUser() {
- return $this->user;
+ public function getStorageLoader() {
+ return $this->loader;
}
/**
@@ -309,4 +314,13 @@ public function getParent() {
public function getName() {
return '';
}
+
+ /**
+ * Get the root folder of the filesystem
+ *
+ * @return \OCP\Files\Folder
+ */
+ public function getRoot() {
+ return $this;
+ }
}
diff --git a/lib/private/files/objectstorefactory.php b/lib/private/files/objectstorefactory.php
new file mode 100644
index 000000000000..07c6593124b2
--- /dev/null
+++ b/lib/private/files/objectstorefactory.php
@@ -0,0 +1,55 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files;
+
+class ObjectStoreFactory extends Factory {
+ /**
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OC\Files\Storage\StorageFactory $storageLoader
+ */
+ protected function mountRoot($mountManager, $storageLoader) {
+ $config = $this->config->getSystemValue('objectstore');
+ // check misconfiguration
+ if (empty($config['class'])) {
+ \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
+ }
+ if (!isset($config['arguments'])) {
+ $config['arguments'] = array();
+ }
+
+ // instantiate object store implementation
+ $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
+ // mount with plain / root object store implementation
+ $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
+
+ $mount = new Mount\MountPoint('\OC\Files\ObjectStore\ObjectStoreStorage', '/', $config['arguments'], $storageLoader);
+ $mountManager->addMount($mount);
+ }
+
+ /**
+ * @param \OC\Files\Mount\Manager $mountManager
+ * @param \OC\Files\Storage\StorageFactory $storageLoader
+ * @param \OCP\IUser $user
+ */
+ protected function mountUserFolder($mountManager, $storageLoader, $user) {
+ $config = $this->config->getSystemValue('objectstore');
+ // sanity checks
+ if (empty($config['class'])) {
+ \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
+ }
+ if (!isset($config['arguments'])) {
+ $config['arguments'] = array();
+ }
+ // instantiate object store implementation
+ $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
+
+ $mount = new Mount\MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $storageLoader);
+ $mountManager->addMount($mount);
+ }
+}
diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php
index 662d4ac03c7c..da52f259f6b6 100644
--- a/lib/private/files/utils/scanner.php
+++ b/lib/private/files/utils/scanner.php
@@ -39,14 +39,21 @@ class Scanner extends PublicEmitter {
*/
protected $db;
+ /**
+ * @var \OCP\Files\Folder
+ */
+ protected $userFolder;
+
/**
* @param string $user
* @param \OCP\IDBConnection $db
+ * @param \OCP\Files\Folder $userFolder
*/
- public function __construct($user, $db) {
+ public function __construct($user, $db, $userFolder) {
$this->user = $user;
$this->propagator = new ChangePropagator(new View(''));
$this->db = $db;
+ $this->userFolder = $userFolder;
}
/**
@@ -56,12 +63,11 @@ public function __construct($user, $db) {
* @return \OC\Files\Mount\MountPoint[]
*/
protected function getMounts($dir) {
- //TODO: move to the node based fileapi once that's done
- \OC_Util::tearDownFS();
- \OC_Util::setupFS($this->user);
- $absolutePath = Filesystem::getView()->getAbsolutePath($dir);
+ /** @var \OC\Files\Node\Root $root */
+ $root = $this->userFolder->getRoot();
+ $mountManager = $root->getMountManager();
+ $absolutePath=$this->userFolder->getFullPath($dir);
- $mountManager = Filesystem::getMountManager();
$mounts = $mountManager->findIn($absolutePath);
$mounts[] = $mountManager->find($absolutePath);
$mounts = array_reverse($mounts); //start with the mount of $dir
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 53e13396621f..4e26fe88d739 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1001,9 +1001,6 @@ private function shouldEmitHooks($path = '') {
if ($path && Cache\Scanner::isPartialFile($path)) {
return false;
}
- if (!Filesystem::$loaded) {
- return false;
- }
$defaultRoot = Filesystem::getRoot();
if ($defaultRoot === null) {
return false;
diff --git a/lib/private/image.php b/lib/private/image.php
index 2484aeecc63f..95a6b0afeef6 100644
--- a/lib/private/image.php
+++ b/lib/private/image.php
@@ -545,7 +545,7 @@ public function loadFromFile($imagePath = false) {
default:
// this is mostly file created from encrypted file
- $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
+ $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents($imagePath));
$iType = IMAGETYPE_PNG;
$this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
break;
diff --git a/lib/private/server.php b/lib/private/server.php
index 4264c70905cf..d3cf1a10ab0f 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -13,6 +13,7 @@
use OC\Diagnostics\QueryLogger;
use OC\Mail\Mailer;
use OC\Memcache\ArrayCache;
+use OC\Files\Storage\StorageFactory;
use OC\Security\CertificateManager;
use OC\Files\Node\Root;
use OC\Files\View;
@@ -55,15 +56,27 @@ function __construct($webRoot) {
$tagMapper = $c->query('TagMapper');
return new TagManager($tagMapper, $c->getUserSession());
});
+ $this->registerService('StorageFactory', function () {
+ return new StorageFactory();
+ });
+ $this->registerService('FilesystemFactory', function (Server $c) {
+ \OC_App::loadApps(array('filesystem'));
+ $config = $c->getConfig();
+ $mountProvider = $c->getMountProviderCollection();
+ $storageFactory = $c->query('StorageFactory');
+ if ($config->getSystemValue('objectstore', false)) {
+ return new \OC\Files\ObjectStoreFactory($config, $mountProvider, $storageFactory);
+ } else {
+ return new \OC\Files\Factory($config, $mountProvider, $storageFactory);
+ }
+ });
$this->registerService('RootFolder', function (Server $c) {
- // TODO: get user and user manager from container as well
- $user = \OC_User::getUser();
- /** @var $c SimpleContainer */
- $userManager = $c->query('UserManager');
- $user = $userManager->get($user);
- $manager = \OC\Files\Filesystem::getMountManager();
- $view = new View();
- return new Root($manager, $view, $user);
+ $userSession = $c->getUserSession();
+ $user = $userSession->getUser();
+ $factory = $c->getFilesystemFactory();
+ \OC\Files\Filesystem::$activeUser = $user;
+ \OC\Files\Filesystem::$loaded = true;
+ return $factory->getRoot();
});
$this->registerService('UserManager', function (Server $c) {
$config = $c->getConfig();
@@ -277,8 +290,8 @@ function __construct($webRoot) {
$c->getL10N('lib', $language)
);
});
- $this->registerService('MountConfigManager', function () {
- $loader = \OC\Files\Filesystem::getLoader();
+ $this->registerService('MountConfigManager', function (Server $c) {
+ $loader = $c->query('StorageFactory');
return new \OC\Files\Config\MountProviderCollection($loader);
});
$this->registerService('IniWrapper', function ($c) {
@@ -386,6 +399,15 @@ function getAvatarManager() {
return $this->query('AvatarManager');
}
+ /**
+ * Returns filesystem factory
+ *
+ * @return \OC\Files\Factory
+ */
+ function getFilesystemFactory() {
+ return $this->query('FilesystemFactory');
+ }
+
/**
* Returns the root folder of ownCloud's data directory
*
@@ -395,6 +417,21 @@ function getRootFolder() {
return $this->query('RootFolder');
}
+ /**
+ * Setup the filesystem for a user
+ *
+ * @param string $userId
+ */
+ function setupFilesystem($userId) {
+ /** @var \OC\Files\Node\Root $root */
+ $this->getRootFolder();
+ $user = $this->getUserManager()->get($userId);
+ if ($user) {
+ $factory = \OC::$server->getFilesystemFactory();
+ $factory->getUserFolder($user);
+ }
+ }
+
/**
* Returns a view to ownCloud's files folder
*
@@ -407,42 +444,13 @@ function getUserFolder($userId = null) {
if (!$user) {
return null;
}
- $userId = $user->getUID();
} else {
$user = $this->getUserManager()->get($userId);
}
- \OC\Files\Filesystem::initMountPoints($userId);
- $dir = '/' . $userId;
- $root = $this->getRootFolder();
- $folder = null;
-
- if (!$root->nodeExists($dir)) {
- $folder = $root->newFolder($dir);
- } else {
- $folder = $root->get($dir);
- }
-
- $dir = '/files';
- if (!$folder->nodeExists($dir)) {
- $folder = $folder->newFolder($dir);
+ $factory = $this->getFilesystemFactory();
- if (\OCP\App::isEnabled('files_encryption')) {
- // disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
- }
-
- \OC_Util::copySkeleton($user, $folder);
-
- if (\OCP\App::isEnabled('files_encryption')) {
- // re-enable proxy - our work is done
- \OC_FileProxy::$enabled = $proxyStatus;
- }
- } else {
- $folder = $folder->get($dir);
- }
-
- return $folder;
+ $userFolder = $factory->getUserFolder($user);
+ return $userFolder->get('/files');
}
/**
diff --git a/lib/private/util.php b/lib/private/util.php
index a2024fddc3d2..fa5b9724347b 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -14,126 +14,27 @@ class OC_Util {
protected static function getAppManager() {
return \OC::$server->getAppManager();
}
-
- private static function initLocalStorageRootFS() {
- // mount local file backend as root
- $configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
- //first set up the local "root" storage
- \OC\Files\Filesystem::initMounts();
- if (!self::$rootMounted) {
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/');
- self::$rootMounted = true;
- }
- }
-
- /**
- * mounting an object storage as the root fs will in essence remove the
- * necessity of a data folder being present.
- * TODO make home storage aware of this and use the object storage instead of local disk access
- *
- * @param array $config containing 'class' and optional 'arguments'
- */
- private static function initObjectStoreRootFS($config) {
- // check misconfiguration
- if (empty($config['class'])) {
- \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
- }
- if (!isset($config['arguments'])) {
- $config['arguments'] = array();
- }
-
- // instantiate object store implementation
- $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
- // mount with plain / root object store implementation
- $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
-
- // mount object storage as root
- \OC\Files\Filesystem::initMounts();
- if (!self::$rootMounted) {
- \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
- self::$rootMounted = true;
- }
- }
-
+
/**
* Can be set up
*
- * @param string $user
+ * @param string $userId
* @return boolean
* @description configure the initial filesystem based on the configuration
*/
- public static function setupFS($user = '') {
- //setting up the filesystem twice can only lead to trouble
- if (self::$fsSetup) {
- return false;
- }
-
- \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
-
- // If we are not forced to load a specific user we load the one that is logged in
- if ($user == "" && OC_User::isLoggedIn()) {
- $user = OC_User::getUser();
- }
-
- // load all filesystem apps before, so no setup-hook gets lost
- OC_App::loadApps(array('filesystem'));
-
- // the filesystem will finish when $user is not empty,
- // mark fs setup here to avoid doing the setup from loading
- // OC_Filesystem
- if ($user != '') {
- self::$fsSetup = true;
- }
-
- //check if we are using an object storage
- $objectStore = OC_Config::getValue('objectstore');
- if (isset($objectStore)) {
- self::initObjectStoreRootFS($objectStore);
+ public static function setupFS($userId = '') {
+ /** @var \OC\Files\Node\Root $root */
+ \OC::$server->getRootFolder();
+ if ($userId) {
+ $user = \OC::$server->getUserManager()->get($userId);
} else {
- self::initLocalStorageRootFS();
+ $user = \OC::$server->getUserSession()->getUser();
}
-
- if ($user != '' && !OCP\User::userExists($user)) {
- \OC::$server->getEventLogger()->end('setup_fs');
- return false;
- }
-
- //if we aren't logged in, there is no use to set up the filesystem
- if ($user != "") {
- \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
- // set up quota for home storages, even for other users
- // which can happen when using sharing
-
- /**
- * @var \OC\Files\Storage\Storage $storage
- */
- if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
- || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
- ) {
- if (is_object($storage->getUser())) {
- $user = $storage->getUser()->getUID();
- $quota = OC_Util::getUserQuota($user);
- if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
- return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
- }
- }
- }
-
- return $storage;
- });
-
- $userDir = '/' . $user . '/files';
-
- //jail the user into his "home" directory
- \OC\Files\Filesystem::init($user, $userDir);
-
- //trigger creation of user home and /files folder
- \OC::$server->getUserFolder($user);
-
- OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
+ if ($user) {
+ $factory = \OC::$server->getFilesystemFactory();
+ \OC\Files\Filesystem::$activeUser = $user;
+ $factory->getUserFolder($user);
}
- \OC::$server->getEventLogger()->end('setup_fs');
- return true;
}
/**
@@ -198,35 +99,13 @@ public static function getUserQuota($user) {
if ($userQuota === 'default') {
$userQuota = $config->getAppValue('files', 'default_quota', 'none');
}
- if($userQuota === 'none') {
+ if ($userQuota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
- }else{
+ } else {
return OC_Helper::computerFileSize($userQuota);
}
}
- /**
- * copies the skeleton to the users /files
- *
- * @param \OC\User\User $user
- * @param \OCP\Files\Folder $userDirectory
- */
- public static function copySkeleton(\OC\User\User $user, \OCP\Files\Folder $userDirectory) {
-
- $skeletonDirectory = \OCP\Config::getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
-
- if (!empty($skeletonDirectory)) {
- \OCP\Util::writeLog(
- 'files_skeleton',
- 'copying skeleton for '.$user->getUID().' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
- \OCP\Util::DEBUG
- );
- self::copyr($skeletonDirectory, $userDirectory);
- // update the file cache
- $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
- }
- }
-
/**
* copies a directory recursively by using streams
*
@@ -509,8 +388,8 @@ public static function checkServer(\OCP\IConfig $config) {
$errors[] = array(
'error' => $l->t('Cannot write into "config" directory'),
'hint' => $l->t('This can usually be fixed by '
- . '%sgiving the webserver write access to the config directory%s.',
- array('', ''))
+ . '%sgiving the webserver write access to the config directory%s.',
+ array('', ''))
);
}
@@ -523,9 +402,9 @@ public static function checkServer(\OCP\IConfig $config) {
$errors[] = array(
'error' => $l->t('Cannot write into "apps" directory'),
'hint' => $l->t('This can usually be fixed by '
- . '%sgiving the webserver write access to the apps directory%s'
- . ' or disabling the appstore in the config file.',
- array('', ''))
+ . '%sgiving the webserver write access to the apps directory%s'
+ . ' or disabling the appstore in the config file.',
+ array('', ''))
);
}
}
@@ -560,7 +439,7 @@ public static function checkServer(\OCP\IConfig $config) {
if (!OC_Util::isSetLocaleWorking()) {
$errors[] = array(
'error' => $l->t('Setting locale to %s failed',
- array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
+ array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
. 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')),
'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')
);
@@ -669,7 +548,7 @@ public static function checkServer(\OCP\IConfig $config) {
$errors[] = array(
'error' => $l->t('PHP %s or higher is required.', '5.4.0'),
'hint' => $l->t('Please ask your server administrator to update PHP to the latest version.'
- . ' Your PHP version is no longer supported by ownCloud and the PHP community.')
+ . ' Your PHP version is no longer supported by ownCloud and the PHP community.')
);
$webServerRestart = true;
}
@@ -743,7 +622,7 @@ public static function checkDatabaseVersion() {
$errors[] = array(
'error' => $l->t('Error occurred while checking PostgreSQL version'),
'hint' => $l->t('Please make sure you have PostgreSQL >= 9 or'
- . ' check the logs for more information about the error')
+ . ' check the logs for more information about the error')
);
}
}
@@ -839,7 +718,7 @@ public static function checkDataDirectoryValidity($dataDirectory) {
$errors[] = array(
'error' => $l->t('Data directory (%s) is invalid', array($dataDirectory)),
'hint' => $l->t('Please check that the data directory contains a file' .
- ' ".ocdata" in its root.')
+ ' ".ocdata" in its root.')
);
}
return $errors;
@@ -1116,7 +995,7 @@ public static function isHtaccessWorking() {
// creating a test file
$testFile = OC::$server->getConfig()->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
- if (file_exists($testFile)) {// already running this test, possible recursive call
+ if (file_exists($testFile)) { // already running this test, possible recursive call
return false;
}
@@ -1244,7 +1123,7 @@ public static function obEnd() {
* @deprecated Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
*/
public static function generateRandomBytes($length = 30) {
- return \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
+ return \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
}
/**
diff --git a/lib/public/files/ihomestorage.php b/lib/public/files/ihomestorage.php
index 717ef9467507..dcf9d2398144 100644
--- a/lib/public/files/ihomestorage.php
+++ b/lib/public/files/ihomestorage.php
@@ -20,5 +20,10 @@
namespace OCP\Files;
interface IHomeStorage {
-
+ /**
+ * Get the user to which the home storage belongs
+ *
+ * @return \OCP\IUser
+ */
+ public function getUser();
}
diff --git a/lib/public/files/node.php b/lib/public/files/node.php
index 74355d10e801..bb728e04f396 100644
--- a/lib/public/files/node.php
+++ b/lib/public/files/node.php
@@ -197,4 +197,11 @@ public function getParent();
* @return string
*/
public function getName();
+
+ /**
+ * Get the root folder of the filesystem
+ *
+ * @return \OCP\Files\Folder
+ */
+ public function getRoot();
}
diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php
index 388ba5fa6ac5..4fec74437a8f 100644
--- a/lib/public/files/storage.php
+++ b/lib/public/files/storage.php
@@ -298,6 +298,7 @@ public function getLocalFile($path);
* @return string|false
*/
public function getLocalFolder($path);
+
/**
* check if a file or folder has been updated since $time
*
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 20345e612125..da4cd4897de0 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -78,6 +78,13 @@ function getTagManager();
*/
function getRootFolder();
+ /**
+ * Setup the filesystem for a user
+ *
+ * @param string $userId
+ */
+ function setupFilesystem($userId);
+
/**
* Returns a view to ownCloud's files folder
*
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index d51322036c87..3c78a796a0b1 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -47,14 +47,7 @@ protected function setUp() {
// 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);
+ $this->clearFileSystem();
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -74,11 +67,6 @@ protected function setUp() {
protected function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('cachedirectory', $this->datadir);
-
- // Restore the original mount point
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->storage, array(), '/');
parent::tearDown();
}
diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php
index 3822a714d5a5..3962e2d01520 100644
--- a/tests/lib/cache/usercache.php
+++ b/tests/lib/cache/usercache.php
@@ -44,13 +44,7 @@ protected function setUp() {
//}
//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);
+ $this->clearFileSystem();
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -70,12 +64,6 @@ protected function setUp() {
protected function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('cachedirectory', $this->datadir);
-
- // Restore the original mount point
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->storage, array(), '/');
-
parent::tearDown();
}
}
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
index 99cacca8e95a..ba71b192d9ee 100644
--- a/tests/lib/files/cache/updaterlegacy.php
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -34,7 +34,9 @@ class UpdaterLegacy extends \Test\TestCase {
private static $user;
- protected function setUp() {
+ private $userBackend;
+
+ public function setUp() {
parent::setUp();
// remember files_encryption state
@@ -61,10 +63,14 @@ protected function setUp() {
self::$user = $this->getUniqueID();
}
- \OC_User::createUser(self::$user, 'password');
+ if (!$this->userBackend) {
+ $this->userBackend = new \OC_User_Dummy();
+ $this->userBackend->createUser(self::$user, 'foo');
+ }
+ \OC_User::useBackend($this->userBackend);
\OC_User::setUserId(self::$user);
- Filesystem::init(self::$user, '/' . self::$user . '/files');
+ \OC_Util::setupFS(self::$user);
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php
index eec24d9f4c66..f92399b7a49c 100644
--- a/tests/lib/files/etagtest.php
+++ b/tests/lib/files/etagtest.php
@@ -12,9 +12,6 @@
use OCP\Share;
class EtagTest extends \Test\TestCase {
- private $datadir;
-
- private $tmpDir;
private $uid;
@@ -23,9 +20,6 @@ class EtagTest extends \Test\TestCase {
*/
private $userBackend;
- /** @var \OC\Files\Storage\Storage */
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
@@ -34,47 +28,29 @@ protected function 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 tearDown() {
- \OC_Config::setValue('datadirectory', $this->datadir);
- \OC_User::setUserId($this->uid);
- \OC_Util::setupFS($this->uid);
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
-
- parent::tearDown();
}
public function testNewUser() {
$user1 = $this->getUniqueID('user_');
$this->userBackend->createUser($user1, '');
- \OC_Util::tearDownFS();
- \OC_User::setUserId($user1);
- \OC_Util::setupFS($user1);
- Filesystem::mkdir('/folder');
- Filesystem::mkdir('/folder/subfolder');
- Filesystem::file_put_contents('/foo.txt', 'asd');
- Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
- Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
+ Filesystem::mount('\OC\Files\Storage\Temporary', array(), '/' . $user1);
+ $folder = \OC::$server->getUserFolder($user1);
+ $folder->newFolder('/folder');
+ $folder->newFolder('/folder/subfolder');
+ $folder->newFile('/foo.txt')->putContent('asd');
+ $folder->newFile('/folder/bar.txt')->putContent('fgh');
+ $folder->newFile('/folder/subfolder/qwerty.txt')->putContent('jkl');
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
- $originalEtags = $this->getEtags($files);
+ $originalEtags = $this->getEtags($folder, $files);
- $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection());
+ $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getUserFolder($user1));
$scanner->backgroundScan('/');
- $newEtags = $this->getEtags($files);
+ $newEtags = $this->getEtags($folder, $files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
@@ -82,13 +58,15 @@ public function testNewUser() {
}
/**
+ * @param \OCP\Files\Folder $folder
* @param string[] $files
+ * @return string[]
*/
- private function getEtags($files) {
+ private function getEtags($folder, $files) {
$etags = array();
foreach ($files as $file) {
- $info = Filesystem::getFileInfo($file);
- $etags[$file] = $info['etag'];
+ $node = $folder->get($file);
+ $etags[$file] = $node->getEtag();
}
return $etags;
}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 7bf59315d77d..2225bb42ccd6 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -245,7 +245,7 @@ public function testHooks() {
$user = \OC_User::getUser();
} else {
$user = $this->getUniqueID();
- \OC\Files\Filesystem::init($user, '/' . $user . '/files');
+ \OC_Util::setupFS($user);
}
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
@@ -266,22 +266,6 @@ public function testHooks() {
// \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
}
- /**
- * Tests that a local storage mount is used when passed user
- * does not exist.
- */
- public function testLocalMountWhenUserDoesNotExist() {
- $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $userId = $this->getUniqueID('user_');
-
- \OC\Files\Filesystem::initMountPoints($userId);
-
- $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
-
- $this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Local'));
- $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId());
- }
-
/**
* Tests that the home storage is used for the user's mount point
*/
@@ -290,7 +274,7 @@ public function testHomeMount() {
\OC_User::createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ \OC::$server->setupFilesystem($userId);
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
@@ -315,7 +299,7 @@ public function testLegacyHomeMount() {
$cache = $localStorage->getCache();
\OC_User::createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ \OC::$server->setupFilesystem($userId);
$homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
@@ -342,7 +326,7 @@ public function testMountDefaultCacheDir() {
\OC_Config::setValue('cache_path', '');
\OC_User::createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ \OC::$server->setupFilesystem($userId);
$this->assertEquals(
'/' . $userId . '/',
@@ -369,7 +353,7 @@ public function testMountExternalCacheDir() {
\OC_Config::setValue('cache_path', $cachePath);
\OC_User::createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ \OC::$server->setupFilesystem($userId);
$this->assertEquals(
'/' . $userId . '/cache/',
diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php
index e3b8019b4cad..5edf9d19f98e 100644
--- a/tests/lib/files/node/file.php
+++ b/tests/lib/files/node/file.php
@@ -8,10 +8,9 @@
namespace Test\Files\Node;
+use OC\Files\Storage\StorageFactory as Loader;
use OC\Files\FileInfo;
use OCP\Files\NotFoundException;
-use OCP\Files\NotPermittedException;
-use OC\Files\View;
class File extends \Test\TestCase {
private $user;
@@ -87,7 +86,7 @@ public function testDeleteHooks() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener);
@@ -144,7 +143,7 @@ public function testGetContent() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called');
@@ -267,7 +266,7 @@ public function testFOpenRead() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called');
@@ -303,7 +302,7 @@ public function testFOpenWrite() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, new $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hooksCalled = 0;
$hook = function ($file) use (&$hooksCalled) {
@@ -344,7 +343,7 @@ public function testFOpenReadNotPermitted() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hook = function ($file) {
throw new \Exception('Hooks are not supposed to be called');
@@ -371,7 +370,7 @@ public function testFOpenReadWriteNoReadPermissions() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hook = function () {
throw new \Exception('Hooks are not supposed to be called');
@@ -398,7 +397,7 @@ public function testFOpenReadWriteNoWritePermissions() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, new $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$hook = function () {
throw new \Exception('Hooks are not supposed to be called');
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index 54b26ebdfe18..64672585d18a 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -12,9 +12,8 @@
use OC\Files\FileInfo;
use OC\Files\Mount\MountPoint;
use OC\Files\Node\Node;
+use OC\Files\Storage\StorageFactory as Loader;
use OCP\Files\NotFoundException;
-use OCP\Files\NotPermittedException;
-use OC\Files\View;
class Folder extends \Test\TestCase {
private $user;
@@ -86,7 +85,7 @@ public function testDeleteHooks() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener);
@@ -395,9 +394,21 @@ public function testSearch() {
->with('/bar/foo')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$result = $node->search('qw');
@@ -411,7 +422,7 @@ public function testSearchInRoot() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn'), array($manager, $view, $this->user));
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -435,9 +446,21 @@ public function testSearchInRoot() {
->with('')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'files')));
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('files'));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->will($this->returnValue($mount));
$result = $root->search('qw');
$this->assertEquals(1, count($result));
@@ -473,9 +496,21 @@ public function testSearchByTag() {
->with('/bar/foo')
->will($this->returnValue(array()));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$result = $node->searchByTag('tag1', 'user1');
@@ -534,9 +569,21 @@ public function testSearchSubStorages() {
->with('/bar/foo')
->will($this->returnValue(array($subMount)));
- $view->expects($this->once())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, 'foo')));
+ $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mount->expects($this->once())
+ ->method('getStorage')
+ ->will($this->returnValue($storage));
+
+ $mount->expects($this->once())
+ ->method('getInternalPath')
+ ->will($this->returnValue('foo'));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->will($this->returnValue($mount));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
@@ -560,7 +607,7 @@ public function testGetById() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, new Loader(), $view));
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -603,7 +650,7 @@ public function testGetByIdOutsideFolder() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, new Loader(), $view));
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -641,7 +688,7 @@ public function testGetByIdMultipleStorages() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, new Loader(), $view));
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index 456a4a0e287f..48293dc0c18a 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -8,8 +8,7 @@
namespace Test\Files\Node;
-use OC\Files\Cache\Cache;
-use OC\Files\Node\Root;
+use OC\Files\Storage\StorageFactory as Loader;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\User;
@@ -37,7 +36,7 @@ protected function setUp() {
parent::setUp();
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
- \OC\Files\Filesystem::init('', '');
+ \OC_Util::setupFS();
\OC\Files\Filesystem::clearMounts();
$manager = \OC\Files\Filesystem::getMountManager();
@@ -51,7 +50,7 @@ protected function setUp() {
$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);
+ $this->root = new \OC\Files\Node\Root($manager, new Loader(), $this->view);
$storage = new Temporary(array());
$subStorage = new Temporary(array());
$this->storages[] = $storage;
diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php
index 01ed84c4a065..6699c830ad5f 100644
--- a/tests/lib/files/node/node.php
+++ b/tests/lib/files/node/node.php
@@ -8,6 +8,7 @@
namespace Test\Files\Node;
+use OC\Files\Storage\StorageFactory as Loader;
use OC\Files\FileInfo;
class Node extends \Test\TestCase {
@@ -294,7 +295,7 @@ public function testTouchHooks() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$root->listen('\OC\Files', 'preTouch', $preListener);
$root->listen('\OC\Files', 'postTouch', $postListener);
diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php
index a763428209c0..810a9c36dea8 100644
--- a/tests/lib/files/node/root.php
+++ b/tests/lib/files/node/root.php
@@ -8,6 +8,7 @@
namespace Test\Files\Node;
+use OC\Files\Storage\StorageFactory as Loader;
use OC\Files\FileInfo;
use OCP\Files\NotPermittedException;
use OC\Files\Mount\Manager;
@@ -34,7 +35,7 @@ public function testGet() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$view->expects($this->once())
->method('getFileInfo')
@@ -70,7 +71,7 @@ public function testGetNotFound() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$view->expects($this->once())
->method('file_exists')
@@ -90,7 +91,7 @@ public function testGetInvalidPath() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$root->get('/../foo');
}
@@ -104,7 +105,7 @@ public function testGetNoStorages() {
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
- $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+ $root = new \OC\Files\Node\Root($manager, new Loader(), $view);
$root->get('/bar/foo');
}
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index 65ddfe47514c..7b24a68b2605 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -64,7 +64,8 @@ public function testReuseExistingRoot() {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $userFolder = $this->getMock('\OCP\Files\Folder');
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $userFolder);
$scanner->addMount($mount);
$scanner->scan('');
@@ -86,7 +87,8 @@ public function testReuseExistingFile() {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $userFolder = $this->getMock('\OCP\Files\Folder');
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $userFolder);
$scanner->addMount($mount);
$scanner->scan('');
@@ -113,7 +115,8 @@ public function testChangePropagator() {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection());
+ $userFolder = $this->getMock('\OCP\Files\Folder');
+ $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $userFolder);
$originalPropagator = $scanner->getPropagator();
$scanner->setPropagator($propagator);
$scanner->addMount($mount);
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php
index 8b5f41fc94cb..2091ec71c16d 100644
--- a/tests/lib/helperstorage.php
+++ b/tests/lib/helperstorage.php
@@ -27,7 +27,7 @@ protected function setUp() {
$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_Util::setupFS($this->user);
\OC\Files\Filesystem::clearMounts();
$this->storageMock = null;
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 2a6761403f45..b424a0907705 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -32,9 +32,7 @@ protected function setUp() {
// 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->clearFileSystem();
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/'.$this->user);
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 2b4540120d25..263218cefad5 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -54,6 +54,15 @@ protected static function getUniqueID($prefix = '', $length = 13) {
);
}
+ /**
+ * Setup a clean filesystem
+ */
+ protected function clearFileSystem() {
+ \OC\Files\Filesystem::clearMounts();
+ $storage = new \OC\Files\Storage\Temporary(array());
+ \OC\Files\Filesystem::mount($storage, array(), '/');
+ }
+
public static function tearDownAfterClass() {
$dataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');