From e163543cbbd10ed4595ba6568dc849a42d9e4c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 4 Jul 2018 16:50:47 +0200 Subject: [PATCH] empty path has no parents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- lib/private/Files/Cache/Propagator.php | 7 +++++++ tests/lib/Files/Cache/PropagatorTest.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) 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');