This commit is contained in:
Morris Jobke 2021-06-02 19:25:21 +02:00 committed by GitHub
commit 75ba0f0a5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -62,6 +62,10 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
private $logger;
protected $type = 'file_storage';
protected $genericObjectStore;
protected $appDataObjectStore;
public function __construct($params) {
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
$this->objectStore = $params['objectstore'];
@ -81,6 +85,14 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$this->mkdir('/');
}
// bootstrap object store for app data
$systemConfig = \OC::$server->getSystemConfig();
$appDataStorageConfig = $systemConfig->getValue('appdata_objectstore_multibucket', null);
if ($appDataStorageConfig && isset($appDataStorageConfig['arguments'])) {
$this->genericObjectStore = $params['objectstore'];
$this->appDataObjectStore = new $appDataStorageConfig['class']($appDataStorageConfig['arguments']);
}
$this->logger = \OC::$server->getLogger();
}
@ -207,6 +219,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
if ($stat['mimetype'] === 'httpd/unix-directory') {
return $this->rmdir($path);
}
$this->verifyStorage($path);
try {
$this->objectStore->deleteObject($this->getURN($stat['fileid']));
} catch (\Exception $ex) {
@ -290,7 +303,26 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
}
}
/**
* Verify and set the current object store for files and appdata files
*
* @param $path
*/
private function verifyStorage($path) {
if ($this->appDataObjectStore !== null) {
$isAppDataFile = $this->isAppDataFile($path);
if ($isAppDataFile && $this->type !== 'appdata_storage') {
$this->type = 'appdata_storage';
$this->objectStore = $this->appDataObjectStore;
} else if (!$isAppDataFile && $this->type !== 'file_storage') {
$this->type = 'file_storage';
$this->objectStore = $this->genericObjectStore;
}
}
}
public function fopen($path, $mode) {
$this->verifyStorage($path);
$path = $this->normalizePath($path);
if (strrpos($path, '.') !== false) {
@ -448,6 +480,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
}
public function writeStream(string $path, $stream, int $size = null): int {
$this->verifyStorage($path);
$stat = $this->stat($path);
if (empty($stat)) {
// create new file
@ -532,6 +565,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
}
public function getObjectStore(): IObjectStore {
$this->verifyStorage($path);
return $this->objectStore;
}
@ -594,6 +628,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$targetUrn = $this->getURN($targetId);
try {
$this->verifyStorage($path);
$this->objectStore->copyObject($sourceUrn, $targetUrn);
} catch (\Exception $e) {
$cache->remove($to);