Skip to content
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
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Server;
use Psr\Log\LoggerInterface;

class AmazonS3 extends \OC\Files\Storage\Common {
class AmazonS3 extends \OC\Files\Storage\Common implements IStorageDebugInfo {
use S3ConnectionTrait;
use S3ObjectTrait;

Expand Down Expand Up @@ -787,4 +788,8 @@ public function hasUpdated($path, $time) {
return true;
}
}

function debugInfo(): string {
return "s3 bucket {$this->bucket}";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
use OC\Files\Storage\PolyFill\CopyDirectory;
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageNotAvailableException;
use Psr\Log\LoggerInterface;

class FTP extends Common {
class FTP extends Common implements IStorageDebugInfo {
use CopyDirectory;

private $root;
Expand Down Expand Up @@ -377,4 +378,8 @@ public function getDirectoryContent($directory): \Traversable {
yield $data;
}
}

function debugInfo(): string {
return "ftp share {$this->username}@{$this->host}/{$this->root}";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use phpseclib\Net\SFTP\Stream;

/**
* Uses phpseclib's Net\SFTP class and the Net\SFTP\Stream stream wrapper to
* provide access to SFTP servers.
*/
class SFTP extends Common {
class SFTP extends Common implements IStorageDebugInfo {
private $host;
private $user;
private $root;
Expand Down Expand Up @@ -584,4 +585,8 @@ public function getMetaData($path) {
$keys = ['size', 'mtime', 'mimetype', 'etag', 'storage_mtime', 'permissions', 'name'];
return array_intersect_key($stat, array_flip($keys));
}

function debugInfo(): string {
return "sftp share {$this->user}@{$this->host}/{$this->root}";
}
}
26 changes: 25 additions & 1 deletion apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace OCA\Files_External\Lib\Storage;

use Icewind\SMB\ACL;
use Icewind\SMB\AnonymousAuth;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectException;
Expand All @@ -47,7 +48,9 @@
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\OutOfSpaceException;
use Icewind\SMB\Exception\TimedOutException;
use Icewind\SMB\IAuth;
use Icewind\SMB\IFileInfo;
use Icewind\SMB\KerberosAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Options;
use Icewind\SMB\ServerFactory;
Expand All @@ -64,11 +67,12 @@
use OCP\Files\Notify\IRenameChange;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\INotifyStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException;
use Psr\Log\LoggerInterface;

class SMB extends Common implements INotifyStorage {
class SMB extends Common implements INotifyStorage, IStorageDebugInfo {
/**
* @var \Icewind\SMB\IServer
*/
Expand Down Expand Up @@ -98,10 +102,14 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $checkAcl;

private array $params;
private IAuth $auth;

public function __construct($params) {
if (!isset($params['host'])) {
throw new \Exception('Invalid configuration, no host provided');
}
$this->params = $params;

if (isset($params['auth'])) {
$auth = $params['auth'];
Expand Down Expand Up @@ -133,6 +141,7 @@ public function __construct($params) {
}
}
$serverFactory = new ServerFactory($options);
$this->auth = $auth;
$this->server = $serverFactory->createServer($params['host'], $auth);
$this->share = $this->server->getShare(trim($params['share'], '/'));

Expand Down Expand Up @@ -782,4 +791,19 @@ public function notify($path) {
$shareNotifyHandler = $this->share->notify($this->buildPath($path));
return new SMBNotifyHandler($shareNotifyHandler, $this->root);
}

public function debugInfo(): string {
$share = "//{$this->server->getHost()}/{$this->share->getName()}{$this->root}";
if (isset($this->params['user'])) {
$share = "{$this->params['user']}@$share";
}
if ($this->auth instanceof KerberosAuth) {
$auth = "kerberos";
} else if ($this->auth instanceof AnonymousAuth) {
$auth = "anonymous";
} else {
$auth = "password";
}
return "SMB share $share using $auth authentication";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@
use Icewind\Streams\IteratorDirectory;
use OC\Files\ObjectStore\SwiftFactory;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageBadConfigException;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\ObjectStore\v1\Models\StorageObject;
use Psr\Log\LoggerInterface;

class Swift extends \OC\Files\Storage\Common {
class Swift extends \OC\Files\Storage\Common implements IStorageDebugInfo {
/** @var SwiftFactory */
private $connectionFactory;
/**
Expand Down Expand Up @@ -627,4 +628,8 @@ public function hasUpdated($path, $time) {
public static function checkDependencies() {
return true;
}

function debugInfo(): string {
return "swift bucket {$this->bucket}";
}
}
7 changes: 6 additions & 1 deletion apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\IClientService;
Expand All @@ -60,7 +61,7 @@
use OCP\Server;
use Psr\Log\LoggerInterface;

class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage {
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage, IStorageDebugInfo {
private ICloudId $cloudId;
private string $mountPoint;
private string $token;
Expand Down Expand Up @@ -453,4 +454,8 @@ protected function getDefaultPermissions(string $path): int {
public function free_space($path) {
return parent::free_space("");
}

function debugInfo(): string {
return "external share from {$this->getRemoteUser()}@{$this->getRemote()}";
}
}
38 changes: 37 additions & 1 deletion apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage {
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage, IStorageDebugInfo {
/** @var \OCP\Share\IShare */
private $superShare;

Expand Down Expand Up @@ -562,4 +563,39 @@ public function getUnjailedPath($path) {
$this->init();
return parent::getUnjailedPath($path);
}

function debugInfo(): string {
$share = $this->getShare();
$shares = $this->groupedShares;
$sharedBy = array_map(function (IShare $share) {
$shareType = $this->formatShareType($share);
if ($shareType) {
return $share->getSharedBy() . " (via " . $shareType . " " . $share->getSharedWith() . ")";
} else {
return $share->getSharedBy();
}
}, $shares);
$description = "shared by " . implode(', ', $sharedBy);
if ($share->getSharedBy() !== $share->getShareOwner()) {
$description .= " owned by " . $share->getShareOwner();
}
return $description;
}

private function formatShareType(IShare $share): ?string {
switch ($share->getShareType()) {
case IShare::TYPE_GROUP:
return "group";
case IShare::TYPE_CIRCLE:
return "circle";
case IShare::TYPE_DECK:
return "deck";
case IShare::TYPE_ROOM:
return "room";
case IShare::TYPE_USER:
return null;
default:
return "Unknown (" . $share->getShareType() . ")";
}
}
}
50 changes: 10 additions & 40 deletions core/Command/Info/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -123,48 +124,17 @@ public function formatPermissions(string $type, int $permissions): string {
*/
public function formatMountType(IMountPoint $mountPoint): string {
$storage = $mountPoint->getStorage();
if ($storage && $storage->instanceOfStorage(IHomeStorage::class)) {
return "home storage";
} elseif ($mountPoint instanceof SharedMount) {
$share = $mountPoint->getShare();
$shares = $mountPoint->getGroupedShares();
$sharedBy = array_map(function (IShare $share) {
$shareType = $this->formatShareType($share);
if ($shareType) {
return $share->getSharedBy() . " (via " . $shareType . " " . $share->getSharedWith() . ")";
} else {
return $share->getSharedBy();
}
}, $shares);
$description = "shared by " . implode(', ', $sharedBy);
if ($share->getSharedBy() !== $share->getShareOwner()) {
$description .= " owned by " . $share->getShareOwner();
}
return $description;
} elseif ($mountPoint instanceof GroupMountPoint) {
return "groupfolder " . $mountPoint->getFolderId();
} elseif ($mountPoint instanceof ExternalMountPoint) {
return "external storage " . $mountPoint->getStorageConfig()->getId();

if ($mountPoint instanceof ExternalMountPoint) {
$prefix = "external storage " . $mountPoint->getStorageConfig()->getId() . ": ";
} elseif ($mountPoint instanceof CircleMount) {
return "circle";
$prefix = "circle: ";
}
return get_class($mountPoint);
}

public function formatShareType(IShare $share): ?string {
switch ($share->getShareType()) {
case IShare::TYPE_GROUP:
return "group";
case IShare::TYPE_CIRCLE:
return "circle";
case IShare::TYPE_DECK:
return "deck";
case IShare::TYPE_ROOM:
return "room";
case IShare::TYPE_USER:
return null;
default:
return "Unknown (" . $share->getShareType() . ")";
if ($storage->instanceOfStorage(IStorageDebugInfo::class)) {
Copy link
Member

Choose a reason for hiding this comment

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

technically the complaint is right, the interface is not an IStorage. Does instance of not work here? Or method_exists in worst case?

/** @var IStorageDebugInfo $storage */
return $prefix . $storage->debugInfo();
} else {
return $prefix . get_class($mountPoint);
}
}

Expand Down
69 changes: 69 additions & 0 deletions core/Command/Info/UserMounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Robin Appelman <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\Core\Command\Info;

use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UserMounts extends Command {
public function __construct(
private FileUtils $fileUtils,
private IUserManager $userManager,
private IRootFolder $rootFolder,
) {
parent::__construct();
}

protected function configure(): void {
$this
->setName('info:user:mounts')
->setDescription('list mounted storages available for a user')
->addArgument('user', InputArgument::REQUIRED, "User id to get mounted storages for");
}

public function execute(InputInterface $input, OutputInterface $output): int {
$userId = $input->getArgument('user');
$user = $this->userManager->get($userId);
if (!$user) {
$output->writeln("<error>user $userId not found</error>");
return 1;
}

$userFolder = $this->rootFolder->getUserFolder($userId);
$mounts = $this->rootFolder->getMountsIn($userFolder->getPath());
$mounts[] = $userFolder->getMountPoint();
usort($mounts, fn (IMountPoint $a, IMountPoint $b) => $a->getMountPoint() <=> $b->getMountPoint());

foreach ($mounts as $mount) {
$mountInfo = $this->fileUtils->formatMountType($mount);
$output->writeln("<info>{$mount->getMountPoint()}</info>: $mountInfo");
}
return 0;
}
}
1 change: 1 addition & 0 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@

$application->add(\OC::$server->get(OC\Core\Command\Info\File::class));
$application->add(\OC::$server->get(OC\Core\Command\Info\Space::class));
$application->add(\OC::$server->get(OC\Core\Command\Info\UserMounts::class));

$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class)));
Expand Down
Loading