summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-10-23 10:15:46 +0200
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2023-10-31 15:17:15 +0000
commitc713b9edbac7fd2023905e0a14604558b24c299f (patch)
treed471501dd8999de3b3518d56d120e4260547cac6 /apps
parente9189e07953487e6bcd3c655c3271a05e9ebb298 (diff)
downloadnextcloud-server-c713b9edbac7fd2023905e0a14604558b24c299f.tar.gz
nextcloud-server-c713b9edbac7fd2023905e0a14604558b24c299f.zip
fix(files_external): on case insensitive system, block case change
When a file/directory is renamed to the same name with only case change, the rename fail. We block this kind of rename. The user will have to rename to another name first. Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/lib/Lib/Backend/SMB.php5
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php19
2 files changed, 24 insertions, 0 deletions
diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php
index bf73c5b40f8..6c879676088 100644
--- a/apps/files_external/lib/Lib/Backend/SMB.php
+++ b/apps/files_external/lib/Lib/Backend/SMB.php
@@ -59,6 +59,11 @@ class SMB extends Backend {
(new DefinitionParameter('show_hidden', $l->t('Show hidden files')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('case_sensitive', $l->t('Case sensitive file system')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN)
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL)
+ ->setDefaultValue(true)
+ ->setTooltip($l->t('Disabling it will allow to use a case insentive file system, but comes with a performance penalty')),
(new DefinitionParameter('check_acl', $l->t('Verify ACL access when listing files')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->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 e0e4659e668..a83887fcda6 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -93,6 +93,8 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $showHidden;
+ private bool $caseSensitive;
+
/** @var bool */
protected $checkAcl;
@@ -132,6 +134,7 @@ class SMB extends Common implements INotifyStorage {
$this->root = rtrim($this->root, '/') . '/';
$this->showHidden = isset($params['show_hidden']) && $params['show_hidden'];
+ $this->caseSensitive = (bool) ($params['case_sensitive'] ?? true);
$this->checkAcl = isset($params['check_acl']) && $params['check_acl'];
$this->statCache = new CappedMemoryCache();
@@ -318,6 +321,12 @@ class SMB extends Common implements INotifyStorage {
if ($this->isRootDir($source) || $this->isRootDir($target)) {
return false;
}
+ if ($this->caseSensitive === false
+ && mb_strtolower($target) === mb_strtolower($source)
+ ) {
+ // Forbid changing case only on case-insensitive file system
+ return false;
+ }
$absoluteSource = $this->buildPath($source);
$absoluteTarget = $this->buildPath($target);
@@ -667,6 +676,16 @@ class SMB extends Common implements INotifyStorage {
public function file_exists($path) {
try {
+ if ($this->caseSensitive === false) {
+ $filename = basename($path);
+ $siblings = $this->getDirectoryContent(dirname($this->buildPath($path)));
+ foreach ($siblings as $sibling) {
+ if ($sibling['name'] === $filename) {
+ return true;
+ }
+ }
+ return false;
+ }
$this->getFileInfo($path);
return true;
} catch (\OCP\Files\NotFoundException $e) {