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

delay getting the home dir of a user untill needed #33597

Closed
wants to merge 1 commit 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
16 changes: 14 additions & 2 deletions lib/private/Files/Storage/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a constant ?

should we use a value even more cryptic ?

$this->setDataDir($this->user->getHome());
}

return parent::getSourcePath($path);
}


public function getId() {
return $this->id;
}
Expand Down
19 changes: 12 additions & 7 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down