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

don't always check if we need to setup the object store root #38415

Merged
merged 1 commit into from
May 24, 2023
Merged
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
24 changes: 18 additions & 6 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ public function __construct($params) {
if (isset($params['validateWrites'])) {
$this->validateWrites = (bool)$params['validateWrites'];
}
//initialize cache with root directory in cache
if (!$this->is_dir('/')) {
$this->mkdir('/');
}

$this->logger = \OC::$server->getLogger();
}

public function mkdir($path) {
public function mkdir($path, bool $force = false) {
$path = $this->normalizePath($path);
if ($this->file_exists($path)) {
if (!$force && $this->file_exists($path)) {
$this->logger->warning("Tried to create an object store folder that already exists: $path");
return false;
}
Expand Down Expand Up @@ -246,6 +242,13 @@ public function stat($path) {
if ($cacheEntry instanceof CacheEntry) {
return $cacheEntry->getData();
} else {
if ($path === '') {
$this->mkdir('', true);
$cacheEntry = $this->getCache()->get($path);
if ($cacheEntry instanceof CacheEntry) {
return $cacheEntry->getData();
}
}
return false;
}
}
Expand Down Expand Up @@ -357,6 +360,12 @@ public function fopen($path, $mode) {
case 'wb':
case 'w+':
case 'wb+':
$dirName = dirname($path);
$parentExists = $this->is_dir($dirName);
if (!$parentExists) {
return false;
}

$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
Expand Down Expand Up @@ -469,6 +478,9 @@ public function needsPartFile() {

public function file_put_contents($path, $data) {
$handle = $this->fopen($path, 'w+');
if (!$handle) {
return false;
}
$result = fwrite($handle, $data);
fclose($handle);
return $result;
Expand Down