Skip to content

Commit 27fd8e4

Browse files
committed
fix(DAV): fix getNodeForPath cache
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 03a2947 commit 27fd8e4

6 files changed

Lines changed: 58 additions & 3 deletions

File tree

.patches/fix-cache-for-node.diff

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/lib/DAV/Tree.php b/lib/DAV/Tree.php
2+
index 65b4583ceb..1483e1bc51 100644
3+
--- a/lib/DAV/Tree.php
4+
+++ b/lib/DAV/Tree.php
5+
@@ -62,9 +62,21 @@ public function getNodeForPath($path)
6+
return $this->rootNode;
7+
}
8+
9+
- $parts = explode('/', $path);
10+
$node = $this->rootNode;
11+
12+
+ // look for any cached parent and collect the parts below the parent
13+
+ $parts = [];
14+
+ $remainingPath = $path;
15+
+ do {
16+
+ list($remainingPath, $baseName) = Uri\split($remainingPath);
17+
+ array_unshift($parts, $baseName);
18+
+
19+
+ if (isset($this->cache[$remainingPath])) {
20+
+ $node = $this->cache[$remainingPath];
21+
+ break;
22+
+ }
23+
+ } while ('' !== $remainingPath);
24+
+
25+
while (count($parts)) {
26+
if (!($node instanceof ICollection)) {
27+
throw new Exception\NotFound('Could not find node at path: '.$path);

composer.patches.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"patches": {
3+
"sabre/dav": {
4+
"Fix getNodeForPath cache": ".patches/fix-cache-for-node.diff"
5+
}
6+
37
}
48
}

composer/installed.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,6 +3912,11 @@
39123912
"bin/naturalselection"
39133913
],
39143914
"type": "library",
3915+
"extra": {
3916+
"patches_applied": {
3917+
"Fix getNodeForPath cache": ".patches/fix-cache-for-node.diff"
3918+
}
3919+
},
39153920
"installation-source": "dist",
39163921
"autoload": {
39173922
"psr-4": {

composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => 'nextcloud/3rdparty',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => 'd7b9f6f5f0513adc3ed652eb84b1822fb5b53032',
6+
'reference' => '330abb953111fee49cd2577b42dcd54712bdb8b0',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../',
99
'aliases' => array(),
@@ -310,7 +310,7 @@
310310
'nextcloud/3rdparty' => array(
311311
'pretty_version' => 'dev-master',
312312
'version' => 'dev-master',
313-
'reference' => 'd7b9f6f5f0513adc3ed652eb84b1822fb5b53032',
313+
'reference' => '330abb953111fee49cd2577b42dcd54712bdb8b0',
314314
'type' => 'library',
315315
'install_path' => __DIR__ . '/../',
316316
'aliases' => array(),

sabre/dav/PATCHES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches)
2+
Patches applied to this directory:
3+
4+
Fix getNodeForPath cache
5+
Source: .patches/fix-cache-for-node.diff
6+
7+

sabre/dav/lib/DAV/Tree.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,21 @@ public function getNodeForPath($path)
6262
return $this->rootNode;
6363
}
6464

65-
$parts = explode('/', $path);
6665
$node = $this->rootNode;
6766

67+
// look for any cached parent and collect the parts below the parent
68+
$parts = [];
69+
$remainingPath = $path;
70+
do {
71+
list($remainingPath, $baseName) = Uri\split($remainingPath);
72+
array_unshift($parts, $baseName);
73+
74+
if (isset($this->cache[$remainingPath])) {
75+
$node = $this->cache[$remainingPath];
76+
break;
77+
}
78+
} while ('' !== $remainingPath);
79+
6880
while (count($parts)) {
6981
if (!($node instanceof ICollection)) {
7082
throw new Exception\NotFound('Could not find node at path: '.$path);

0 commit comments

Comments
 (0)