mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
Merge pull request #33458 from nextcloud/object-store-validate-write
allow disabling object store write check
This commit is contained in:
commit
5e71875626
3 changed files with 20 additions and 1 deletions
|
|
@ -61,6 +61,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|||
|
||||
private $logger;
|
||||
|
||||
/** @var bool */
|
||||
protected $validateWrites = true;
|
||||
|
||||
public function __construct($params) {
|
||||
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
|
||||
$this->objectStore = $params['objectstore'];
|
||||
|
|
@ -75,6 +78,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|||
if (isset($params['objectPrefix'])) {
|
||||
$this->objectPrefix = $params['objectPrefix'];
|
||||
}
|
||||
if (isset($params['validateWrites'])) {
|
||||
$this->validateWrites = (bool)$params['validateWrites'];
|
||||
}
|
||||
//initialize cache with root directory in cache
|
||||
if (!$this->is_dir('/')) {
|
||||
$this->mkdir('/');
|
||||
|
|
@ -522,7 +528,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|||
if ($exists) {
|
||||
$this->getCache()->update($fileId, $stat);
|
||||
} else {
|
||||
if ($this->objectStore->objectExists($urn)) {
|
||||
if (!$this->validateWrites || $this->objectStore->objectExists($urn)) {
|
||||
$this->getCache()->move($uploadPath, $path);
|
||||
} else {
|
||||
$this->getCache()->remove($uploadPath);
|
||||
|
|
|
|||
|
|
@ -37,4 +37,8 @@ class ObjectStoreStorageOverwrite extends ObjectStoreStorage {
|
|||
public function getObjectStore(): IObjectStore {
|
||||
return $this->objectStore;
|
||||
}
|
||||
|
||||
public function setValidateWrites(bool $validate) {
|
||||
$this->validateWrites = $validate;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,6 +181,15 @@ class ObjectStoreStorageTest extends Storage {
|
|||
$this->assertFalse($this->instance->file_exists('test.txt'));
|
||||
}
|
||||
|
||||
public function testWriteObjectSilentFailureNoCheck() {
|
||||
$objectStore = $this->instance->getObjectStore();
|
||||
$this->instance->setObjectStore(new FailWriteObjectStore($objectStore));
|
||||
$this->instance->setValidateWrites(false);
|
||||
|
||||
$this->instance->file_put_contents('test.txt', 'foo');
|
||||
$this->assertTrue($this->instance->file_exists('test.txt'));
|
||||
}
|
||||
|
||||
public function testDeleteObjectFailureKeepCache() {
|
||||
$objectStore = $this->instance->getObjectStore();
|
||||
$this->instance->setObjectStore(new FailDeleteObjectStore($objectStore));
|
||||
|
|
|
|||
Loading…
Reference in a new issue