Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Cleanup filesystem setup code #11091

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files/ajax/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/command/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>$path</info>");
Expand Down
2 changes: 1 addition & 1 deletion apps/files/tests/ajax_rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions apps/files_encryption/lib/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
15 changes: 14 additions & 1 deletion apps/files_encryption/lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions apps/files_encryption/lib/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
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/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 @@ -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() ) {
Expand Down Expand Up @@ -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');
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 @@ -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)) {
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 @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion apps/files_versions/lib/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions apps/files_versions/tests/versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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 @@ -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');
}
Expand Down
Loading