From 612b2a45f8f76fef4c370713a9976c40b55d5ebf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 18 Aug 2022 11:30:58 +0200 Subject: [PATCH] delay getting the home dir of a user untill needed for cache-only operations we don't actually need to know the home directory Signed-off-by: Robin Appelman --- lib/private/Files/Storage/Home.php | 16 ++++++++++++++-- lib/private/Files/Storage/Local.php | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index 5427bc425c262..7742af89c312f 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -49,12 +49,24 @@ class Home extends Local implements \OCP\Files\IHomeStorage { */ public function __construct($arguments) { $this->user = $arguments['user']; - $datadir = $this->user->getHome(); $this->id = 'home::' . $this->user->getUID(); - parent::__construct(['datadir' => $datadir]); + // use a placeholder datadir until we actually need to caluclate a source path + // + // this allows using this storage with a LazyUser without having to get the real user + // as long as only cache operations are done + parent::__construct(['datadir' => '/tmp/empty/placeholder/']); } + public function getSourcePath($path) { + if ($this->datadir == '/tmp/empty/placeholder/') { + $this->setDataDir($this->user->getHome()); + } + + return parent::getSourcePath($path); + } + + public function getId() { return $this->id; } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 9daa351782517..a9aaa5f9780d2 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -75,7 +75,18 @@ public function __construct($arguments) { if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) { throw new \InvalidArgumentException('No data directory set for local storage'); } - $this->datadir = str_replace('//', '/', $arguments['datadir']); + + $this->setDataDir($arguments['datadir']); + $this->config = \OC::$server->get(IConfig::class); + $this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class); + $this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022); + + // support Write-Once-Read-Many file systems + $this->unlinkOnTruncate = $this->config->getSystemValue('localstorage.unlink_on_truncate', false); + } + + protected function setDataDir(string $dataDir) { + $this->datadir = str_replace('//', '/', $dataDir); // some crazy code uses a local storage on root... if ($this->datadir === '/') { $this->realDataDir = $this->datadir; @@ -87,12 +98,6 @@ public function __construct($arguments) { $this->datadir .= '/'; } $this->dataDirLength = strlen($this->realDataDir); - $this->config = \OC::$server->get(IConfig::class); - $this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class); - $this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022); - - // support Write-Once-Read-Many file systems - $this->unlinkOnTruncate = $this->config->getSystemValue('localstorage.unlink_on_truncate', false); } public function __destruct() {