Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for shared file IDs on SMB storage #21049

Closed
wants to merge 2 commits into from
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
3 changes: 3 additions & 0 deletions apps/files_external/lib/Lib/Backend/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct(IL10N $l, Password $legacyAuth) {
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL)
->setTooltip($l->t("Check the ACL's of each file or folder inside a directory to filter out items where the user has no read permissions, comes with a performance penalty")),
(new DefinitionParameter('shared',$l->t('Shared storage')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
(new DefinitionParameter('timeout', $l->t('Timeout')))
->setType(DefinitionParameter::VALUE_HIDDEN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
Expand Down
10 changes: 10 additions & 0 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $checkAcl;

/** @var bool */
protected $isSharedStorage;

public function __construct($params) {
if (!isset($params['host'])) {
throw new \Exception('Invalid configuration, no host provided');
Expand Down Expand Up @@ -131,6 +134,7 @@ public function __construct($params) {

$this->showHidden = isset($params['show_hidden']) && $params['show_hidden'];
$this->checkAcl = isset($params['check_acl']) && $params['check_acl'];
$this->isSharedStorage = isset($params['shared']) && $params['shared'];

$this->statCache = new CappedMemoryCache();
parent::__construct($params);
Expand All @@ -153,6 +157,12 @@ public function getId() {
// FIXME: double slash to keep compatible with the old storage ids,
// failure to do so will lead to creation of a new storage id and
// loss of shares from the storage

// If this is shared storage, generate the same file IDs for all users
if ($this->isSharedStorage) {
return 'smb::' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
}

return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
}

Expand Down
13 changes: 13 additions & 0 deletions apps/files_external/tests/Storage/SmbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ public function testStorageId() {
$this->instance = null;
}

public function testSharedStorageId() {
$this->instance = new SMB([
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$this->instance = new SMB([
$instance = new SMB([

'host' => 'testhost',
'user' => 'testuser',
'password' => 'somepass',
'share' => 'someshare',
'root' => 'someroot',
'shared' => true
]);
$this->assertEquals('smb::testhost//someshare//someroot/', $this->instance->getId());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$this->assertEquals('smb::testhost//someshare//someroot/', $this->instance->getId());
$this->assertEquals('smb::testhost//someshare//someroot/', $instance->getId());

$this->instance = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$this->instance = null;

}

public function testNotifyGetChanges() {
$notifyHandler = $this->instance->notify('');
sleep(1); //give time for the notify to start
Expand Down