Skip to content

Commit 4f2abbd

Browse files
committed
remove some unneeded normalizePath calls
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 970ac3d commit 4f2abbd

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

apps/files_sharing/lib/SharedStorage.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function __construct($arguments) {
112112

113113
parent::__construct([
114114
'storage' => null,
115-
'root' => null,
115+
'root' => '',
116116
]);
117117
}
118118

@@ -292,12 +292,16 @@ public function fopen($path, $mode) {
292292
case 'xb':
293293
case 'a':
294294
case 'ab':
295-
$creatable = $this->isCreatable(dirname($path));
295+
$parent = dirname($path);
296+
if ($parent === '.') {
297+
$parent = '';
298+
}
299+
$creatable = $this->isCreatable($parent);
296300
$updatable = $this->isUpdatable($path);
297301
// if neither permissions given, no need to continue
298302
if (!$creatable && !$updatable) {
299303
if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
300-
$updatable = $this->isUpdatable(dirname($path));
304+
$updatable = $this->isUpdatable($parent);
301305
}
302306

303307
if (!$updatable) {

lib/private/Files/Cache/Updater.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ private function updateStorageMTimeOnly($internalPath) {
255255
private function correctParentStorageMtime($internalPath) {
256256
$parentId = $this->cache->getParentId($internalPath);
257257
$parent = dirname($internalPath);
258+
if ($parent === '.') {
259+
$parent = '';
260+
}
258261
if ($parentId != -1) {
259262
$mtime = $this->storage->filemtime($parent);
260263
if ($mtime !== false) {

lib/private/Files/Mount/MountPoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function getInternalPath($path) {
246246
* @return string
247247
*/
248248
private function formatPath($path) {
249-
$path = Filesystem::normalizePath($path);
249+
$path = '/' . trim($path, '/');
250250
if (strlen($path) > 1) {
251251
$path .= '/';
252252
}

lib/private/Files/Node/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class Node implements INode {
7070
* @param FileInfo $fileInfo
7171
*/
7272
public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) {
73-
if (Filesystem::normalizePath($view->getRoot()) !== '/') {
74-
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
73+
if ($view->getRoot() !== '') {
74+
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set: ' . $view->getRoot());
7575
}
7676
$this->view = $view;
7777
$this->root = $root;

lib/private/Files/Storage/Wrapper/Jail.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
*/
4343
class Jail extends Wrapper {
4444
/**
45-
* @var string
45+
* Root of the jail, without trailing slash
4646
*/
47-
protected $rootPath;
47+
protected string $rootPath;
4848

4949
/**
5050
* @param array $arguments ['storage' => $storage, 'root' => $root]
@@ -54,11 +54,18 @@ class Jail extends Wrapper {
5454
*/
5555
public function __construct($arguments) {
5656
parent::__construct($arguments);
57-
$this->rootPath = $arguments['root'];
57+
$this->rootPath = trim($arguments['root'], '/');
5858
}
5959

6060
public function getUnjailedPath($path) {
61-
return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
61+
$path = trim($path, '/');
62+
if ($this->rootPath === '') {
63+
return $path;
64+
} elseif ($path === '') {
65+
return $this->rootPath;
66+
} else {
67+
return $this->rootPath . '/' . $path;
68+
}
6269
}
6370

6471
/**
@@ -70,9 +77,7 @@ public function getUnjailedStorage() {
7077

7178

7279
public function getJailedPath($path) {
73-
$root = rtrim($this->rootPath, '/') . '/';
74-
75-
if ($path !== $this->rootPath && !str_starts_with($path, $root)) {
80+
if ($path !== $this->rootPath && !str_starts_with($path, $this->rootPath . '/')) {
7681
return null;
7782
} else {
7883
$path = substr($path, strlen($this->rootPath));

lib/private/Files/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
15221522
$rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
15231523
}
15241524

1525-
$rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
1525+
$rootEntry['path'] = substr($path . '/' . $rootEntry['name'], strlen($user) + 2); // full path without /$user/
15261526

15271527
// if sharing was disabled for the user we remove the share permissions
15281528
if (\OCP\Util::isSharingDisabledForUser()) {

lib/private/legacy/OC_Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
491491
if (!$view) {
492492
throw new \OCP\Files\NotFoundException();
493493
}
494-
$fullPath = Filesystem::normalizePath($view->getAbsolutePath($path));
494+
$fullPath = rtrim($view->getAbsolutePath($path), '/');
495495

496496
$cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude');
497497
if ($useCache) {

0 commit comments

Comments
 (0)