diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-09-17 10:44:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-17 10:44:31 +0200 |
commit | 57a5baa88f005b0f1e77b9d3a6fd5a40aea68f3e (patch) | |
tree | 10f93f70f39b3f40052f3b7a249bc67d17768934 /lib | |
parent | f0bf7990f8b7daa6b9de1f046d163b60ab0296b2 (diff) | |
parent | dc13f9cc1e3d8dce1c18d2c7920afe99b7bfa475 (diff) | |
download | nextcloud-server-57a5baa88f005b0f1e77b9d3a6fd5a40aea68f3e.tar.gz nextcloud-server-57a5baa88f005b0f1e77b9d3a6fd5a40aea68f3e.zip |
Merge pull request #48094 from nextcloud/fix/storage/get-owner-false
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Node/Folder.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Node/Root.php | 19 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/HomeObjectStoreStorage.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Storage/Common.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Storage/Home.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Availability.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Wrapper.php | 9 | ||||
-rw-r--r-- | lib/private/Files/View.php | 44 | ||||
-rw-r--r-- | lib/private/Lockdown/Filesystem/NullStorage.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/OC_Helper.php | 3 | ||||
-rw-r--r-- | lib/public/Files/Storage/IStorage.php | 2 |
12 files changed, 63 insertions, 56 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index ca256b09d33..d8344f3d5bd 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -253,7 +253,7 @@ class Folder extends Node implements \OCP\Files\Folder { $owner = null; $ownerId = $storage->getOwner($cacheEntry['internalPath']); - if (!empty($ownerId)) { + if ($ownerId !== false) { // Cache the user manager (for performance) if ($this->userManager === null) { $this->userManager = \OCP\Server::get(IUserManager::class); diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 416adc7f374..dbe03a4cfbf 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -28,6 +28,7 @@ use OCP\ICache; use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -477,9 +478,23 @@ class Root extends Folder implements IRootFolder { $pathRelativeToMount = substr($internalPath, strlen($rootInternalPath)); $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); $absolutePath = rtrim($mount->getMountPoint() . $pathRelativeToMount, '/'); + $storage = $mount->getStorage(); + if ($storage === null) { + return null; + } + $ownerId = $storage->getOwner($pathRelativeToMount); + if ($ownerId !== false) { + $owner = Server::get(IUserManager::class)->get($ownerId); + } else { + $owner = null; + } return $this->createNode($absolutePath, new FileInfo( - $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, - \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) + $absolutePath, + $storage, + $cacheEntry->getPath(), + $cacheEntry, + $mount, + $owner, )); }, $mountsContainingFile); diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php index b543d223f4c..feca1f6b4f5 100644 --- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php @@ -32,13 +32,7 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage return 'object::user:' . $this->user->getUID(); } - /** - * get the owner of a path - * - * @param string $path The path to get the owner - * @return string uid - */ - public function getOwner($path): string { + public function getOwner($path): string|false { return $this->user->getUID(); } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index eb93ab89bc7..181da79cebe 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -390,13 +390,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { return $this->getCache($storage)->getStorageCache(); } - /** - * get the owner of a path - * - * @param string $path The path to get the owner - * @return string|false uid or false - */ - public function getOwner($path) { + public function getOwner($path): string|false { if ($this->owner === null) { $this->owner = \OC_User::getUser(); } diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index 0e53e7b28d4..f7151f4a005 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -83,13 +83,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage { return $this->user; } - /** - * get the owner of a path - * - * @param string $path The path to get the owner - * @return string uid or false - */ - public function getOwner($path) { + public function getOwner($path): string|false { return $this->user->getUID(); } } diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index 6bd622e1c1b..0f1abada168 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -373,12 +373,12 @@ class Availability extends Wrapper { } } - /** {@inheritdoc} */ - public function getOwner($path) { + public function getOwner($path): string|false { try { return parent::getOwner($path); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 5673caf834a..46b40b92244 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -370,13 +370,7 @@ class Jail extends Wrapper { return new CacheJail($sourceCache, $this->rootPath); } - /** - * get the user id of the owner of a file or folder - * - * @param string $path - * @return string - */ - public function getOwner($path) { + public function getOwner($path): string|false { return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path)); } diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index f0420f4f16a..2a6d04da849 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -381,14 +381,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->getScanner($path, $storage); } - - /** - * get the user id of the owner of a file or folder - * - * @param string $path - * @return string - */ - public function getOwner($path) { + public function getOwner($path): string|false { return $this->getWrapperStorage()->getOwner($path); } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 336349c680b..80679a9481f 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -28,6 +28,7 @@ use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; use OCP\Files\ReservedWordException; use OCP\IUser; +use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Server; @@ -1364,7 +1365,7 @@ class View { $ownerId = $storage->getOwner($internalPath); $owner = null; - if ($ownerId !== null && $ownerId !== false) { + if ($ownerId !== false) { // ownerId might be null if files are accessed with an access token without file system access $owner = $this->getUserObjectForOwner($ownerId); } @@ -1450,7 +1451,12 @@ class View { if ($sharingDisabled) { $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; } - $owner = $this->getUserObjectForOwner($storage->getOwner($content['path'])); + $ownerId = $storage->getOwner($content['path']); + if ($ownerId !== false) { + $owner = $this->getUserObjectForOwner($ownerId); + } else { + $owner = null; + } return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner); }, $contents); $files = array_combine($fileNames, $fileInfos); @@ -1527,7 +1533,12 @@ class View { $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; } - $owner = $this->getUserObjectForOwner($subStorage->getOwner('')); + $ownerId = $subStorage->getOwner(''); + if ($ownerId !== false) { + $owner = $this->getUserObjectForOwner($ownerId); + } else { + $owner = null; + } $files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner); } } @@ -1644,7 +1655,12 @@ class View { $internalPath = $result['path']; $path = $mountPoint . $result['path']; $result['path'] = substr($mountPoint . $result['path'], $rootLength); - $owner = $userManager->get($storage->getOwner($internalPath)); + $ownerId = $storage->getOwner($internalPath); + if ($ownerId !== false) { + $owner = $userManager->get($ownerId); + } else { + $owner = null; + } $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner); } } @@ -1663,7 +1679,12 @@ class View { $internalPath = $result['path']; $result['path'] = rtrim($relativeMountPoint . $result['path'], '/'); $path = rtrim($mountPoint . $internalPath, '/'); - $owner = $userManager->get($storage->getOwner($internalPath)); + $ownerId = $storage->getOwner($internalPath); + if ($ownerId !== false) { + $owner = $userManager->get($ownerId); + } else { + $owner = null; + } $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner); } } @@ -1676,11 +1697,9 @@ class View { /** * Get the owner for a file or folder * - * @param string $path - * @return string the user id of the owner * @throws NotFoundException */ - public function getOwner($path) { + public function getOwner(string $path): string { $info = $this->getFileInfo($path); if (!$info) { throw new NotFoundException($path . ' not found while trying to get owner'); @@ -1813,7 +1832,12 @@ class View { $mount = $this->getMount($path); $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($this->getAbsolutePath($path)); - $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath)); + $ownerId = $storage->getOwner($internalPath); + if ($ownerId !== false) { + $owner = Server::get(IUserManager::class)->get($ownerId); + } else { + $owner = null; + } return new FileInfo( $this->getAbsolutePath($path), $storage, @@ -1848,7 +1872,7 @@ class View { // Short cut for read-only validation if ($readonly) { - $validator = \OCP\Server::get(FilenameValidator::class); + $validator = Server::get(FilenameValidator::class); if ($validator->isForbidden($fileName)) { $l = \OCP\Util::getL10N('lib'); throw new InvalidPathException($l->t('Filename is a reserved word')); diff --git a/lib/private/Lockdown/Filesystem/NullStorage.php b/lib/private/Lockdown/Filesystem/NullStorage.php index 7175594a01d..00124877e9d 100644 --- a/lib/private/Lockdown/Filesystem/NullStorage.php +++ b/lib/private/Lockdown/Filesystem/NullStorage.php @@ -155,8 +155,8 @@ class NullStorage extends Common { return true; } - public function getOwner($path) { - return null; + public function getOwner($path): string|false { + return false; } public function getCache($path = '', $storage = null) { diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 33cc966da2a..6da063ef2ce 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -541,10 +541,9 @@ class OC_Helper { $relative = 0; } - /** @var string $ownerId */ $ownerId = $storage->getOwner($path); $ownerDisplayName = ''; - if ($ownerId) { + if ($ownerId !== false) { $ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? ''; } diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index d2fd3b75553..2016c273f91 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -414,7 +414,7 @@ interface IStorage { /** * @param string $path path for which to retrieve the owner - * @return string + * @return string|false * @since 9.0.0 */ public function getOwner($path); |