From 28ab39073a8ea942a7c299dc41ddf6023dd093de Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 18 Oct 2011 21:01:49 +0200 Subject: [PATCH] mount filesystems on demand --- lib/filesystem.php | 13 +++++++++---- lib/util.php | 31 +++---------------------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/lib/filesystem.php b/lib/filesystem.php index f84cda20ea..60fd051f30 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -44,6 +44,7 @@ */ class OC_Filesystem{ static private $storages=array(); + static private $mounts=array(); static private $fakeRoot=''; static private $storageTypes=array(); @@ -91,7 +92,7 @@ class OC_Filesystem{ * @param array arguments * @return OC_Filestorage */ - static public function createStorage($type,$arguments){ + static private function createStorage($type,$arguments){ if(!self::hasStorageType($type)){ return false; } @@ -163,11 +164,11 @@ class OC_Filesystem{ * @param OC_Filestorage storage * @param string mountpoint */ - static public function mount($storage,$mountpoint){ + static public function mount($type,$arguments,$mountpoint){ if(substr($mountpoint,0,1)!=='/'){ $mountpoint='/'.$mountpoint; } - self::$storages[self::$fakeRoot.$mountpoint]=$storage; + self::$mounts[self::$fakeRoot.$mountpoint]=array('type'=>$type,'arguments'=>$arguments); } /** @@ -178,6 +179,10 @@ class OC_Filesystem{ static public function getStorage($path){ $mountpoint=self::getMountPoint($path); if($mountpoint){ + if(!isset(self::$storages[$mountpoint])){ + $mount=self::$mounts[$mountpoint]; + self::$storages[$mountpoint]=self::createStorage($mount['type'],$mount['arguments']); + } return self::$storages[$mountpoint]; } } @@ -201,7 +206,7 @@ class OC_Filesystem{ } $path=self::$fakeRoot.$path; $foundMountPoint=''; - foreach(self::$storages as $mountpoint=>$storage){ + foreach(self::$mounts as $mountpoint=>$storage){ if(substr($mountpoint,-1)!=='/'){ $mountpoint=$mountpoint.'/'; } diff --git a/lib/util.php b/lib/util.php index 6f3b7e3428..ec92a98600 100644 --- a/lib/util.php +++ b/lib/util.php @@ -36,42 +36,17 @@ class OC_Util { } if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem - //first set up the local "root" storage and the backupstorage if needed - $rootStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT)); -// if( OC_Config::getValue( "enablebackup", false )){ -// // This creates the Directorys recursively -// if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ -// mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); -// } -// $backupStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); -// $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); -// $rootStorage->addObserver($backup); -// } - OC_Filesystem::mount($rootStorage,'/'); + //first set up the local "root" storage + OC_Filesystem::mount('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared')); - OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/'); + OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/'); OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root"; if( !is_dir( OC::$CONFIG_DATADIRECTORY )){ mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true ); } -// TODO: find a cool way for doing this -// //set up the other storages according to the system settings -// foreach($CONFIG_FILESYSTEM as $storageConfig){ -// if(OC_Filesystem::hasStorageType($storageConfig['type'])){ -// $arguments=$storageConfig; -// unset($arguments['type']); -// unset($arguments['mountpoint']); -// $storage=OC_Filesystem::createStorage($storageConfig['type'],$arguments); -// if($storage){ -// OC_Filesystem::mount($storage,$storageConfig['mountpoint']); -// } -// } -// } - //jail the user into his "home" directory OC_Filesystem::chroot("/$user/$root"); $quotaProxy=new OC_FileProxy_Quota();