Skip to content

Commit

Permalink
type fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 3, 2022
1 parent 5347915 commit c54aa00
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 45 deletions.
2 changes: 2 additions & 0 deletions apps/files_sharing/lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
namespace OCA\Files_Sharing;

use OC\Files\Mount\MountPoint;
use OCP\Constants;
use OCP\Share\IShare;

Expand Down Expand Up @@ -105,6 +106,7 @@ private static function renameChildren($oldPath, $newPath) {
$mountManager = \OC\Files\Filesystem::getMountManager();
$mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath);
foreach ($mountedShares as $mount) {
/** @var MountPoint $mount */
if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
$mountPoint = $mount->getMountPoint();
$target = str_replace($absOldPath, $absNewPath, $mountPoint);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Cache/CappedMemoryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function get($key) {

/**
* @param string $key
* @param T$value
* @param T $value
* @param int $ttl
* @return bool
*/
Expand Down Expand Up @@ -89,7 +89,7 @@ public function &offsetGet($offset) {

/**
* @param string $key
* @param T$value
* @param T $value
* @return void
*/
public function offsetSet($offset, $value): void {
Expand Down
16 changes: 2 additions & 14 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@
namespace OC\Files;

use OC\Cache\CappedMemoryCache;
use OC\Files\Config\MountProviderCollection;
use OC\Files\Mount\MountPoint;
use OC\Lockdown\Filesystem\NullStorage;
use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;

Expand Down Expand Up @@ -262,11 +258,7 @@ public static function getMountPoint($path) {
\OC_Util::setupFS();
}
$mount = self::$mounts->find($path);
if ($mount) {
return $mount->getMountPoint();
} else {
return '';
}
return $mount->getMountPoint();
}

/**
Expand Down Expand Up @@ -322,11 +314,7 @@ public static function getMountByNumericId($id) {
*/
public static function resolvePath($path) {
$mount = self::getMountManager()->find($path);
if ($mount) {
return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
} else {
return [null, null];
}
return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
}

public static function init($user, $root) {
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ public function find(string $path): IMountPoint {
if (isset($this->mounts[$mountPoint])) {
$this->pathCache[$path] = $this->mounts[$mountPoint];
return $this->mounts[$mountPoint];
}

if ($current === '') {
throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
} elseif ($current === '') {
break;
}

$current = dirname($current);
if ($current === '.' || $current === '/') {
$current = '';
}
}

throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,36 +271,36 @@ public function getInternalPath() {
* @return int
*/
public function getId() {
return null;
return 0;
}

/**
* @return array
*/
public function stat() {
return null;
return [];
}

/**
* @return int
*/
public function getMTime() {
return null;
return 0;
}

/**
* @param bool $includeMounts
* @return int
*/
public function getSize($includeMounts = true) {
return null;
return 0;
}

/**
* @return string
*/
public function getEtag() {
return null;
return '';
}

/**
Expand Down
6 changes: 2 additions & 4 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,19 @@
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Lockdown\ILockdownManager;

class SetupManager {
private bool $rootSetup = false;
private IEventLogger $eventLogger;
private IMountProviderCollection $mountProviderCollection;
private MountProviderCollection $mountProviderCollection;
private IMountManager $mountManager;
private IUserManager $userManager;
private array $setupUsers = [];
Expand All @@ -66,7 +64,7 @@ class SetupManager {

public function __construct(
IEventLogger $eventLogger,
IMountProviderCollection $mountProviderCollection,
MountProviderCollection $mountProviderCollection,
IMountManager $mountManager,
IUserManager $userManager,
IEventDispatcher $eventDispatcher,
Expand Down
16 changes: 4 additions & 12 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function mkdir($path) {
/**
* remove mount point
*
* @param \OC\Files\Mount\MoveableMount $mount
* @param IMountPoint $mount
* @param string $path relative to data/
* @return boolean
*/
Expand Down Expand Up @@ -719,7 +719,7 @@ public function unlink($path) {
$postFix = (substr($path, -1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
if ($mount and $mount->getInternalPath($absolutePath) === '') {
if ($mount->getInternalPath($absolutePath) === '') {
return $this->removeMount($mount, $absolutePath);
}
if ($this->is_dir($path)) {
Expand Down Expand Up @@ -1383,10 +1383,6 @@ public function getFileInfo($path, $includeMountPoints = true) {
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);

$mount = Filesystem::getMountManager()->find($path);
if (!$mount) {
\OC::$server->getLogger()->warning('Mountpoint not found for path: ' . $path);
return false;
}
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path);
if ($storage) {
Expand Down Expand Up @@ -1488,7 +1484,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '') {

$rootEntry = $subCache->get('');
if (!$rootEntry) {
$subScanner = $subStorage->getScanner('');
$subScanner = $subStorage->getScanner();
try {
$subScanner->scanFile('');
} catch (\OCP\Files\StorageNotAvailableException $e) {
Expand Down Expand Up @@ -1916,14 +1912,10 @@ private function getParents($path) {
* @param string $absolutePath absolute path
* @param bool $useParentMount true to return parent mount instead of whatever
* is mounted directly on the given path, false otherwise
* @return \OC\Files\Mount\MountPoint mount point for which to apply locks
* @return IMountPoint mount point for which to apply locks
*/
private function getMountForLock($absolutePath, $useParentMount = false) {
$results = [];
$mount = Filesystem::getMountManager()->find($absolutePath);
if (!$mount) {
return $results;
}

if ($useParentMount) {
// find out if something is mounted directly on the path
Expand Down
2 changes: 2 additions & 0 deletions lib/public/Files/Events/Node/FilesystemTornDownEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

/**
* Event fired after the filesystem has been torn down
*
* @since 24.0.0
*/
class FilesystemTornDownEvent extends Event {
}
4 changes: 0 additions & 4 deletions tests/lib/Files/Mount/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

use OC\Files\SetupManagerFactory;
use OC\Files\Storage\Temporary;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\IUserManager;

class LongId extends Temporary {
public function getId() {
Expand Down

0 comments on commit c54aa00

Please sign in to comment.