]> source.dussan.org Git - nextcloud-server.git/commitdiff
add option to show hidden files in SMB shares 15786/head
authorRobin Appelman <robin@icewind.nl>
Thu, 23 May 2019 19:23:56 +0000 (21:23 +0200)
committerBackportbot <backportbot-noreply@rullzer.com>
Wed, 29 May 2019 08:21:21 +0000 (08:21 +0000)
Note hidden files can mean different things in smb and the option the the files web ui,
the webui only counts files starting with '.' as hidden, while smb files
can be marked as hidden regardless, any files that are marked as hidden
on smb will thus be shown in the webui regardless of the setting in the files app.

Fixes #15644

Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_external/lib/Lib/Backend/SMB.php
apps/files_external/lib/Lib/Storage/SMB.php

index c871dc69771de62f080d1e25fee741cc4b0e50df..0543247051fd5fc6c38446d36c1260e599c887c4 100644 (file)
@@ -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)
index 760cc9ef98b826ad6197206bddb1097e59b2ece3..0d8c10b316b78c9417e7439fabfd0f13e487b8de 100644 (file)
@@ -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) {