diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php index c871dc6977..0543247051 100644 --- a/apps/files_external/lib/Lib/Backend/SMB.php +++ b/apps/files_external/lib/Lib/Backend/SMB.php @@ -50,6 +50,9 @@ class SMB extends Backend { ->setFlag(DefinitionParameter::FLAG_OPTIONAL), (new DefinitionParameter('domain', $l->t('Domain'))) ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('show_hidden', $l->t('Show hidden files'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) ->addAuthScheme(AuthMechanism::SCHEME_SMB) diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 760cc9ef98..0d8c10b316 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -82,6 +82,9 @@ class SMB extends Common implements INotifyStorage { /** @var ILogger */ protected $logger; + /** @var bool */ + protected $showHidden; + public function __construct($params) { if (!isset($params['host'])) { throw new \Exception('Invalid configuration, no host provided'); @@ -110,6 +113,8 @@ class SMB extends Common implements INotifyStorage { $this->root = '/' . ltrim($this->root, '/'); $this->root = rtrim($this->root, '/') . '/'; + $this->showHidden = isset($params['show_hidden']) && $params['show_hidden']; + $this->statCache = new CappedMemoryCache(); parent::__construct($params); } @@ -184,10 +189,13 @@ class SMB extends Common implements INotifyStorage { } return array_filter($files, function (IFileInfo $file) { try { - if ($file->isHidden()) { + // the isHidden check is done before checking the config boolean to ensure that the metadata is always fetch + // so we trigger the below exceptions where applicable + $hide = $file->isHidden() && !$this->showHidden; + if ($hide) { $this->logger->debug('hiding hidden file ' . $file->getName()); } - return !$file->isHidden(); + return !$hide; } catch (ForbiddenException $e) { $this->logger->logException($e, ['level' => ILogger::DEBUG, 'message' => 'Hiding forbidden entry ' . $file->getName()]); return false; @@ -526,7 +534,7 @@ class SMB extends Common implements INotifyStorage { public function isReadable($path) { try { $info = $this->getFileInfo($path); - return !$info->isHidden(); + return $this->showHidden || !$info->isHidden(); } catch (NotFoundException $e) { return false; } catch (ForbiddenException $e) { @@ -539,7 +547,7 @@ class SMB extends Common implements INotifyStorage { $info = $this->getFileInfo($path); // following windows behaviour for read-only folders: they can be written into // (https://support.microsoft.com/en-us/kb/326549 - "cause" section) - return !$info->isHidden() && (!$info->isReadOnly() || $this->is_dir($path)); + return ($this->showHidden || !$info->isHidden()) && (!$info->isReadOnly() || $this->is_dir($path)); } catch (NotFoundException $e) { return false; } catch (ForbiddenException $e) { @@ -550,7 +558,7 @@ class SMB extends Common implements INotifyStorage { public function isDeletable($path) { try { $info = $this->getFileInfo($path); - return !$info->isHidden() && !$info->isReadOnly(); + return ($this->showHidden || !$info->isHidden()) && !$info->isReadOnly(); } catch (NotFoundException $e) { return false; } catch (ForbiddenException $e) {