summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Cache/Cache.php2
-rw-r--r--lib/private/Files/FileInfo.php8
-rw-r--r--lib/private/Files/ObjectStore/HomeObjectStoreStorage.php3
-rw-r--r--lib/private/Files/ObjectStore/S3ConnectionTrait.php2
-rw-r--r--lib/private/Files/SetupManager.php68
-rw-r--r--lib/private/Files/SetupManagerFactory.php45
-rw-r--r--lib/private/Files/Storage/Home.php3
-rw-r--r--lib/private/Files/View.php13
8 files changed, 64 insertions, 80 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index b632e913c2c..9e475057a36 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -663,7 +663,7 @@ class Cache implements ICache {
$targetPath = $this->normalize($targetPath);
$sourceData = $sourceCache->get($sourcePath);
- if ($sourceData === false) {
+ if (!$sourceData) {
throw new \Exception('Invalid source storage path: ' . $sourcePath);
}
diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php
index d717778133d..18a06e82863 100644
--- a/lib/private/Files/FileInfo.php
+++ b/lib/private/Files/FileInfo.php
@@ -235,7 +235,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
}
/**
- * Return the currently version used for the HMAC in the encryption app
+ * Return the current version used for the HMAC in the encryption app
*
* @return int
*/
@@ -247,11 +247,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
* @return int
*/
public function getPermissions() {
- $perms = (int) $this->data['permissions'];
- if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
- $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
- }
- return $perms;
+ return (int) $this->data['permissions'];
}
/**
diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
index 824adcc1d0e..b361249ff47 100644
--- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
@@ -26,6 +26,7 @@
namespace OC\Files\ObjectStore;
use OC\User\User;
+use OCP\IUser;
class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
/**
@@ -61,7 +62,7 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IH
* @param string $path, optional
* @return \OC\User\User
*/
- public function getUser($path = null) {
+ public function getUser($path = null): IUser {
return $this->user;
}
}
diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php
index deb03571c76..49942b385bc 100644
--- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php
+++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php
@@ -92,7 +92,7 @@ trait S3ConnectionTrait {
if (!isset($params['port']) || $params['port'] === '') {
$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
}
- $params['verify_bucket_exists'] = empty($params['verify_bucket_exists']) ? true : $params['verify_bucket_exists'];
+ $params['verify_bucket_exists'] = $params['verify_bucket_exists'] ?? true;
$this->params = $params;
}
diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php
index 01ce4a1cc59..dfc496524a8 100644
--- a/lib/private/Files/SetupManager.php
+++ b/lib/private/Files/SetupManager.php
@@ -34,9 +34,12 @@ use OC\Files\Storage\Wrapper\Encoding;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\Storage\Wrapper\Quota;
use OC\Lockdown\Filesystem\NullStorage;
+use OC\Share\Share;
+use OC\Share20\ShareDisableChecker;
use OC_App;
use OC_Hook;
use OC_Util;
+use OCA\Files_Sharing\ISharedStorage;
use OCP\Constants;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
@@ -64,52 +67,33 @@ use Psr\Log\LoggerInterface;
class SetupManager {
private bool $rootSetup = false;
- private IEventLogger $eventLogger;
- private MountProviderCollection $mountProviderCollection;
- private IMountManager $mountManager;
- private IUserManager $userManager;
// List of users for which at least one mount is setup
private array $setupUsers = [];
// List of users for which all mounts are setup
private array $setupUsersComplete = [];
/** @var array<string, string[]> */
private array $setupUserMountProviders = [];
- private IEventDispatcher $eventDispatcher;
- private IUserMountCache $userMountCache;
- private ILockdownManager $lockdownManager;
- private IUserSession $userSession;
private ICache $cache;
- private LoggerInterface $logger;
- private IConfig $config;
private bool $listeningForProviders;
private array $fullSetupRequired = [];
private bool $setupBuiltinWrappersDone = false;
public function __construct(
- IEventLogger $eventLogger,
- MountProviderCollection $mountProviderCollection,
- IMountManager $mountManager,
- IUserManager $userManager,
- IEventDispatcher $eventDispatcher,
- IUserMountCache $userMountCache,
- ILockdownManager $lockdownManager,
- IUserSession $userSession,
+ private IEventLogger $eventLogger,
+ private MountProviderCollection $mountProviderCollection,
+ private IMountManager $mountManager,
+ private IUserManager $userManager,
+ private IEventDispatcher $eventDispatcher,
+ private IUserMountCache $userMountCache,
+ private ILockdownManager $lockdownManager,
+ private IUserSession $userSession,
ICacheFactory $cacheFactory,
- LoggerInterface $logger,
- IConfig $config
+ private LoggerInterface $logger,
+ private IConfig $config,
+ private ShareDisableChecker $shareDisableChecker,
) {
- $this->eventLogger = $eventLogger;
- $this->mountProviderCollection = $mountProviderCollection;
- $this->mountManager = $mountManager;
- $this->userManager = $userManager;
- $this->eventDispatcher = $eventDispatcher;
- $this->userMountCache = $userMountCache;
- $this->lockdownManager = $lockdownManager;
- $this->logger = $logger;
- $this->userSession = $userSession;
$this->cache = $cacheFactory->createDistributed('setupmanager::');
$this->listeningForProviders = false;
- $this->config = $config;
$this->setupListeners();
}
@@ -139,15 +123,23 @@ class SetupManager {
return $storage;
});
- Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
- if (!$mount->getOption('enable_sharing', true)) {
- return new PermissionsMask([
- 'storage' => $storage,
- 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
- ]);
+ $reSharingEnabled = Share::isResharingAllowed();
+ $user = $this->userSession->getUser();
+ $sharingEnabledForUser = $user ? !$this->shareDisableChecker->sharingDisabledForUser($user->getUID()) : true;
+ Filesystem::addStorageWrapper(
+ 'sharing_mask',
+ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEnabled, $sharingEnabledForUser) {
+ $sharingEnabledForMount = $mount->getOption('enable_sharing', true);
+ $isShared = $storage->instanceOfStorage(ISharedStorage::class);
+ if (!$sharingEnabledForMount || !$sharingEnabledForUser || (!$reSharingEnabled && $isShared)) {
+ return new PermissionsMask([
+ 'storage' => $storage,
+ 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
+ ]);
+ }
+ return $storage;
}
- return $storage;
- });
+ );
// install storage availability wrapper, before most other wrappers
Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php
index 1d9efbd411f..8589cbdea42 100644
--- a/lib/private/Files/SetupManagerFactory.php
+++ b/lib/private/Files/SetupManagerFactory.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace OC\Files;
+use OC\Share20\ShareDisableChecker;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
@@ -36,40 +37,21 @@ use OCP\Lockdown\ILockdownManager;
use Psr\Log\LoggerInterface;
class SetupManagerFactory {
- private IEventLogger $eventLogger;
- private IMountProviderCollection $mountProviderCollection;
- private IUserManager $userManager;
- private IEventDispatcher $eventDispatcher;
- private IUserMountCache $userMountCache;
- private ILockdownManager $lockdownManager;
- private IUserSession $userSession;
private ?SetupManager $setupManager;
- private ICacheFactory $cacheFactory;
- private LoggerInterface $logger;
- private IConfig $config;
public function __construct(
- IEventLogger $eventLogger,
- IMountProviderCollection $mountProviderCollection,
- IUserManager $userManager,
- IEventDispatcher $eventDispatcher,
- IUserMountCache $userMountCache,
- ILockdownManager $lockdownManager,
- IUserSession $userSession,
- ICacheFactory $cacheFactory,
- LoggerInterface $logger,
- IConfig $config
+ private IEventLogger $eventLogger,
+ private IMountProviderCollection $mountProviderCollection,
+ private IUserManager $userManager,
+ private IEventDispatcher $eventDispatcher,
+ private IUserMountCache $userMountCache,
+ private ILockdownManager $lockdownManager,
+ private IUserSession $userSession,
+ private ICacheFactory $cacheFactory,
+ private LoggerInterface $logger,
+ private IConfig $config,
+ private ShareDisableChecker $shareDisableChecker,
) {
- $this->eventLogger = $eventLogger;
- $this->mountProviderCollection = $mountProviderCollection;
- $this->userManager = $userManager;
- $this->eventDispatcher = $eventDispatcher;
- $this->userMountCache = $userMountCache;
- $this->lockdownManager = $lockdownManager;
- $this->userSession = $userSession;
- $this->cacheFactory = $cacheFactory;
- $this->logger = $logger;
- $this->config = $config;
$this->setupManager = null;
}
@@ -86,7 +68,8 @@ class SetupManagerFactory {
$this->userSession,
$this->cacheFactory,
$this->logger,
- $this->config
+ $this->config,
+ $this->shareDisableChecker,
);
}
return $this->setupManager;
diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php
index 5427bc425c2..5100b15215b 100644
--- a/lib/private/Files/Storage/Home.php
+++ b/lib/private/Files/Storage/Home.php
@@ -26,6 +26,7 @@
namespace OC\Files\Storage;
use OC\Files\Cache\HomePropagator;
+use OCP\IUser;
/**
* Specialized version of Local storage for home directory usage
@@ -94,7 +95,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage {
*
* @return \OC\User\User owner of this home storage
*/
- public function getUser() {
+ public function getUser(): IUser {
return $this->user;
}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 95ad46ec554..0cf5e24616a 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -55,6 +55,7 @@ use OC\User\User;
use OCA\Files_Sharing\SharedMount;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\ConnectionLostException;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\InvalidCharacterInPathException;
@@ -427,10 +428,11 @@ class View {
}
$handle = $this->fopen($path, 'rb');
if ($handle) {
- $chunkSize = 524288; // 512 kB chunks
+ $chunkSize = 524288; // 512 kiB chunks
while (!feof($handle)) {
echo fread($handle, $chunkSize);
flush();
+ $this->checkConnectionStatus();
}
fclose($handle);
return $this->filesize($path);
@@ -483,6 +485,7 @@ class View {
}
echo fread($handle, $len);
flush();
+ $this->checkConnectionStatus();
}
return ftell($handle) - $from;
}
@@ -492,6 +495,14 @@ class View {
return false;
}
+
+ private function checkConnectionStatus(): void {
+ $connectionStatus = \connection_status();
+ if ($connectionStatus !== CONNECTION_NORMAL) {
+ throw new ConnectionLostException("Connection lost. Status: $connectionStatus");
+ }
+ }
+
/**
* @param string $path
* @return mixed