Skip to content

Commit b29bc1e

Browse files
authored
Merge pull request #17281 from nextcloud/backport/17262/stable17
[stable17] dont delete cache entries if deleting an object from object store failed
2 parents 072d51e + ffcb590 commit b29bc1e

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ public function rmdir($path) {
161161
return false;
162162
}
163163

164-
$this->rmObjects($path);
164+
if (!$this->rmObjects($path)) {
165+
return false;
166+
}
165167

166168
$this->getCache()->remove($path);
167169

@@ -172,11 +174,17 @@ private function rmObjects($path) {
172174
$children = $this->getCache()->getFolderContents($path);
173175
foreach ($children as $child) {
174176
if ($child['mimetype'] === 'httpd/unix-directory') {
175-
$this->rmObjects($child['path']);
177+
if (!$this->rmObjects($child['path'])) {
178+
return false;
179+
}
176180
} else {
177-
$this->unlink($child['path']);
181+
if(!$this->unlink($child['path'])) {
182+
return false;
183+
}
178184
}
179185
}
186+
187+
return true;
180188
}
181189

182190
public function unlink($path) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
4+
*
5+
* @license GNU AGPL version 3 or any later version
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
namespace Test\Files\ObjectStore;
23+
24+
25+
use OCP\Files\ObjectStore\IObjectStore;
26+
27+
class FailDeleteObjectStore implements IObjectStore {
28+
private $objectStore;
29+
30+
public function __construct(IObjectStore $objectStore) {
31+
$this->objectStore = $objectStore;
32+
}
33+
34+
public function getStorageId() {
35+
return $this->objectStore->getStorageId();
36+
}
37+
38+
public function readObject($urn) {
39+
return $this->objectStore->readObject($urn);
40+
}
41+
42+
public function writeObject($urn, $stream) {
43+
return $this->objectStore->writeObject($urn, $stream);
44+
}
45+
46+
public function deleteObject($urn) {
47+
throw new \Exception();
48+
}
49+
50+
public function objectExists($urn) {
51+
return $this->objectStore->objectExists($urn);
52+
}
53+
}
54+

tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,29 @@ public function testWriteObjectSilentFailure() {
181181
}
182182
$this->assertFalse($this->instance->file_exists('test.txt'));
183183
}
184+
185+
public function testDeleteObjectFailureKeepCache() {
186+
$objectStore = $this->instance->getObjectStore();
187+
$this->instance->setObjectStore(new FailDeleteObjectStore($objectStore));
188+
$cache = $this->instance->getCache();
189+
190+
$this->instance->file_put_contents('test.txt', 'foo');
191+
192+
$this->assertTrue($cache->inCache('test.txt'));
193+
194+
$this->assertFalse($this->instance->unlink('test.txt'));
195+
196+
$this->assertTrue($cache->inCache('test.txt'));
197+
198+
$this->instance->mkdir('foo');
199+
$this->instance->file_put_contents('foo/test.txt', 'foo');
200+
201+
$this->assertTrue($cache->inCache('foo'));
202+
$this->assertTrue($cache->inCache('foo/test.txt'));
203+
204+
$this->instance->rmdir('foo');
205+
206+
$this->assertTrue($cache->inCache('foo'));
207+
$this->assertTrue($cache->inCache('foo/test.txt'));
208+
}
184209
}

0 commit comments

Comments
 (0)