add option to show hidden files in SMB shares
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>
This commit is contained in:
parent
d467e9129b
commit
74cb5d592d
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue