Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove some unneeded normalizePath calls #41116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions 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 Expand Up @@ -292,12 +292,16 @@ public function fopen($path, $mode) {
case 'xb':
case 'a':
case 'ab':
$creatable = $this->isCreatable(dirname($path));
$parent = dirname($path);
if ($parent === '.') {
$parent = '';
}
$creatable = $this->isCreatable($parent);
$updatable = $this->isUpdatable($path);
// if neither permissions given, no need to continue
if (!$creatable && !$updatable) {
if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
$updatable = $this->isUpdatable(dirname($path));
$updatable = $this->isUpdatable($parent);
}

if (!$updatable) {
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Files/Cache/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ private function updateStorageMTimeOnly($internalPath) {
private function correctParentStorageMtime($internalPath) {
$parentId = $this->cache->getParentId($internalPath);
$parent = dirname($internalPath);
if ($parent === '.') {
$parent = '';
}
if ($parentId != -1) {
$mtime = $this->storage->filemtime($parent);
if ($mtime !== false) {
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
20 changes: 12 additions & 8 deletions lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Cache\Wrapper\JailPropagator;
use OC\Files\Filesystem;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
use OCP\Lock\ILockingProvider;
Expand All @@ -42,9 +41,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 +53,18 @@ class Jail extends Wrapper {
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->rootPath = $arguments['root'];
$this->rootPath = trim($arguments['root'], '/');
}

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

/**
Expand All @@ -70,9 +76,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), '/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if we should skip the normalization here as $path might get passed from public API and is used as a cache key which could trigger the uncached calculation then more often


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