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 <[email protected]>
  • Loading branch information
icewind1991 committed Nov 2, 2023
1 parent b2c0cd9 commit 8f7f696
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
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), '/');

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

0 comments on commit 8f7f696

Please sign in to comment.