Skip to content

Commit

Permalink
Cleanup filesystem setup code
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Sep 15, 2014
1 parent 627252f commit 75bb96a
Show file tree
Hide file tree
Showing 34 changed files with 469 additions and 486 deletions.
2 changes: 1 addition & 1 deletion apps/files/tests/ajax_rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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())
Expand Down
2 changes: 1 addition & 1 deletion apps/files_encryption/hooks/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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();

Expand Down
4 changes: 2 additions & 2 deletions apps/files_encryption/lib/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct($view, $userId, $client = false) {
$this->privateKeyPath =
$this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
// make sure that the owners home is mounted
\OC\Files\Filesystem::initMountPoints($userId);
\OC::$server->setupFilesystem($userId);

if (\OCA\Encryption\Helper::isPublicAccess()) {
$this->keyId = $this->publicShareKeyId;
Expand Down Expand Up @@ -1175,7 +1175,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) {
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/ajax/publicpreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/appinfo/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function removeSharedFolder($mkdirs = true, $chunkSize = 99) {

if ($mkdirs) {
foreach ($unique_users as $user) {
\OC\Files\Filesystem::initMountPoints($user);
\OC::$server->setupFilesystem($user);
if (!$view->file_exists('/' . $user . '/files/Shared')) {
$view->mkdir('/' . $user . '/files/Shared');
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/lib/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function authenticate($linkItem, $password) {
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() ) {
Expand Down Expand Up @@ -166,7 +166,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');
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/share/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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)) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/sharedstorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/lib/trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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');
Expand Down
2 changes: 1 addition & 1 deletion apps/files_versions/lib/versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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');
Expand Down
2 changes: 1 addition & 1 deletion lib/private/cache/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getStorage() {
return $this->storage;
}
if(\OC_User::isLoggedIn()) {
\OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
\OC::$server->setupFilesystem(\OC_User::getUser());
$this->storage = new \OC\Files\View('/' . \OC_User::getUser() . '/cache');
return $this->storage;
}else{
Expand Down
37 changes: 0 additions & 37 deletions lib/private/fileproxy/fileoperations.php

This file was deleted.

147 changes: 147 additions & 0 deletions lib/private/files/factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
/**
* Copyright (c) 2014 Robin Appelman <[email protected]>
* 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\Loader;
use OC\Files\Storage\Wrapper\Quota;
use OCP\Files\FileInfo;

class Factory {
/**
* @var \OCP\IConfig
*/
protected $config;

/**
* @param \OCP\IConfig $config
*/
public function __construct($config) {
$this->config = $config;
}

/**
* @param \OC\Files\Mount\Manager $mountManager
* @param \OC\Files\Storage\Loader $storageLoader
*/
protected function mountRoot($mountManager, $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\Mount('\OC\Files\Storage\Local', '/', array('datadir' => $configDataDirectory), $storageLoader);
$mountManager->addMount($mount);
}

/**
* @param \OC\Files\Mount\Manager $mountManager
* @param \OC\Files\Storage\Loader $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\Mount('\OC\Files\Storage\Home', '/' . $user->getUID(), array(
'datadir' => $user->getHome(),
'user' => $user,
'legacy' => $legacy
), $storageLoader);
$mountManager->addMount($mount);
}

/**
* @param \OC\Files\Mount\Manager $mountManager
* @param \OC\Files\Storage\Loader $storageLoader
* @param \OCP\IUser $user
*/
protected function mountCacheDir($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\Mount('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', array('datadir' => $cacheDir), $storageLoader);
$mountManager->addMount($mount);
}
}

/**
* @param \OCP\IUser $user
*/
protected function copySkeleton($user) {
$userDirectory = $user->getHome() . '/files';
if (!is_dir($userDirectory)) {
mkdir($userDirectory, 0755, true);
$skeletonDirectory = $this->config->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
if (!empty($skeletonDirectory)) {
\OC_Util::copyr($skeletonDirectory, $userDirectory);
}
}
}

/**
* Create the root filesystem
*
* @return \OC\Files\Node\Root
*/
public function createRoot() {
$mountManager = new Manager();
$storageLoader = new Loader();

$storageLoader->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, $storageLoader);
return new Root($mountManager, $storageLoader, new View(''));
}

/**
* Mount the storages for a user
*
* @param \OC\Files\Node\Root $root
* @param \OCP\IUser $user
*/
public function setupForUser($root, $user) {
$mountManager = $root->getMountManager();
$storageLoader = $root->getStorageLoader();
if (is_null($mountManager->getMount('/' . $user->getUID()))) {
$this->mountUserFolder($mountManager, $storageLoader, $user);
$this->mountCacheDir($mountManager, $storageLoader, $user);
\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $user->getHome()));

$this->copySkeleton($user);

\OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user->getUID(), 'user_dir' => $user->getHome() . '/files'));
}
}
}
Loading

0 comments on commit 75bb96a

Please sign in to comment.