Skip to content

Commit

Permalink
Merge pull request #33458 from nextcloud/object-store-validate-write
Browse files Browse the repository at this point in the history
allow disabling object store write check
  • Loading branch information
skjnldsv committed Oct 26, 2022
2 parents 71f6986 + 3357c8e commit 5e71875
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -75,6 +78,9 @@ public function __construct($params) {
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('/');
Expand Down Expand Up @@ -522,7 +528,7 @@ public function writeStream(string $path, $stream, int $size = null): int {
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);
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public function setObjectStore(IObjectStore $objectStore) {
public function getObjectStore(): IObjectStore {
return $this->objectStore;
}

public function setValidateWrites(bool $validate) {
$this->validateWrites = $validate;
}
}
9 changes: 9 additions & 0 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ public function testWriteObjectSilentFailure() {
$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));
Expand Down

0 comments on commit 5e71875

Please sign in to comment.