From d8432f0bdeb714238d737cc8ec73f57e25d7364f Mon Sep 17 00:00:00 2001 From: David Date: Tue, 19 May 2020 15:42:41 -0400 Subject: [PATCH 1/2] Add support for shared file IDs on SMB storage Signed-off-by: David --- apps/files_external/lib/Lib/Backend/SMB.php | 3 +++ apps/files_external/lib/Lib/Storage/SMB.php | 10 ++++++++++ apps/files_external/tests/Storage/SmbTest.php | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php index 5344bf5f78c20..764911b5f2879 100644 --- a/apps/files_external/lib/Lib/Backend/SMB.php +++ b/apps/files_external/lib/Lib/Backend/SMB.php @@ -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), diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index ce37d55612993..c0fb540b90755 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -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'); @@ -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); @@ -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; } diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index 2e2983dad1b50..58d2c1cb6596d 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -96,6 +96,19 @@ public function testStorageId() { $this->instance = null; } + public function testStorageId() { + $this->instance = new SMB([ + 'host' => 'testhost', + 'user' => 'testuser', + 'password' => 'somepass', + 'share' => 'someshare', + 'root' => 'someroot', + 'shared' => true + ]); + $this->assertEquals('smb::testhost//someshare//someroot/', $this->instance->getId()); + $this->instance = null; + } + public function testNotifyGetChanges() { $notifyHandler = $this->instance->notify(''); sleep(1); //give time for the notify to start From 91ae50696ce6f2be3f96fd1ac674838ed0832083 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 19 May 2020 15:48:31 -0400 Subject: [PATCH 2/2] Fix test function name Signed-off-by: David --- apps/files_external/tests/Storage/SmbTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index 58d2c1cb6596d..778594e0cdbdc 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -96,7 +96,7 @@ public function testStorageId() { $this->instance = null; } - public function testStorageId() { + public function testSharedStorageId() { $this->instance = new SMB([ 'host' => 'testhost', 'user' => 'testuser',