Skip to content

Commit

Permalink
remove some unneeded normalizePath calls
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Oct 31, 2023
1 parent 970ac3d commit e4120e2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function __construct($arguments) {

parent::__construct([
'storage' => null,
'root' => null,
'root' => '',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function getInternalPath($path) {
* @return string
*/
private function formatPath($path) {
$path = Filesystem::normalizePath($path);
$path = '/' . trim($path, '/');
if (strlen($path) > 1) {
$path .= '/';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Node implements INode {
* @param FileInfo $fileInfo
*/
public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) {
if (Filesystem::normalizePath($view->getRoot()) !== '/') {
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
if ($view->getRoot() !== '') {
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set: ' . $view->getRoot());
}
$this->view = $view;
$this->root = $root;
Expand Down
16 changes: 9 additions & 7 deletions lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
*/
class Jail extends Wrapper {
/**
* @var string
* Root of the jail, without trailing slash
*/
protected $rootPath;
protected string $rootPath;

/**
* @param array $arguments ['storage' => $storage, 'root' => $root]
Expand All @@ -54,11 +54,15 @@ class Jail extends Wrapper {
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->rootPath = $arguments['root'];
$this->rootPath = rtrim($arguments['root'], '/');
}

public function getUnjailedPath($path) {
return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
if ($this->rootPath === '') {
return $path;
} else {
return $this->rootPath . '/' . trim($path, '/');
}
}

/**
Expand All @@ -70,9 +74,7 @@ public function getUnjailedStorage() {


public function getJailedPath($path) {
$root = rtrim($this->rootPath, '/') . '/';

if ($path !== $this->rootPath && !str_starts_with($path, $root)) {
if ($path !== $this->rootPath && !str_starts_with($path, $this->rootPath . '/')) {
return null;
} else {
$path = substr($path, strlen($this->rootPath));
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
$rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
}

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

// if sharing was disabled for the user we remove the share permissions
if (\OCP\Util::isSharingDisabledForUser()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
if (!$view) {
throw new \OCP\Files\NotFoundException();
}
$fullPath = Filesystem::normalizePath($view->getAbsolutePath($path));
$fullPath = rtrim($view->getAbsolutePath($path), '/');

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

0 comments on commit e4120e2

Please sign in to comment.