diff --git a/lib/private/Files/Cache/Propagator.php b/lib/private/Files/Cache/Propagator.php index 5b9d19163dd2..a7ec27896cef 100644 --- a/lib/private/Files/Cache/Propagator.php +++ b/lib/private/Files/Cache/Propagator.php @@ -62,6 +62,10 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) { $parents = $this->getParents($internalPath); + if (\count($parents) === 0) { + return; + } + if ($this->inBatch) { foreach ($parents as $parent) { $this->addToBatch($parent, $time, $sizeDifference); @@ -99,6 +103,9 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) { } protected function getParents($path) { + if ($path === '') { + return []; + } $parts = \explode('/', $path); $parent = ''; $parents = []; diff --git a/tests/lib/Files/Cache/PropagatorTest.php b/tests/lib/Files/Cache/PropagatorTest.php index 3a73dea9e374..95870ab8cdec 100644 --- a/tests/lib/Files/Cache/PropagatorTest.php +++ b/tests/lib/Files/Cache/PropagatorTest.php @@ -81,6 +81,25 @@ public function testSizePropagation() { } } + public function getParentsProvider() { + return [ + ['', []], + ['foo', ['']], + ['foo/bar', ['', 'foo']], + ['foo/bar/baz.txt', ['', 'foo', 'foo/bar']] + ]; + } + + /** + * @dataProvider getParentsProvider + * @param $path + * @throws \OCP\Files\StorageNotAvailableException + */ + public function testGetParents($path, $expected) { + $propagator = $this->storage->getPropagator(); + self::assertSame($expected, self::invokePrivate($propagator, 'getParents', [$path])); + } + public function testBatchedPropagation() { $this->storage->mkdir('foo/baz'); $this->storage->mkdir('asd');