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

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2023-05-23 14:28:37 +02:00
parent b313e2a507
commit cc0ad25c98
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB

View file

@ -87,17 +87,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
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;
}
@ -246,6 +242,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
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;
}
}
@ -357,6 +360,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
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) {
@ -469,6 +478,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
public function file_put_contents($path, $data) {
$handle = $this->fopen($path, 'w+');
if (!$handle) {
return false;
}
$result = fwrite($handle, $data);
fclose($handle);
return $result;