Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some support for rename on case insensitive local filesystems #40935

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Local extends \OC\Files\Storage\Common {

protected bool $unlinkOnTruncate;

protected bool $caseInsensitive = false;

public function __construct($arguments) {
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
throw new \InvalidArgumentException('No data directory set for local storage');
Expand All @@ -93,6 +95,7 @@ public function __construct($arguments) {
$this->config = \OC::$server->get(IConfig::class);
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
$this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022);
$this->caseInsensitive = $this->config->getSystemValueBool('localstorage.case_insensitive', false);

// support Write-Once-Read-Many file systems
$this->unlinkOnTruncate = $this->config->getSystemValueBool('localstorage.unlink_on_truncate', false);
Expand Down Expand Up @@ -162,13 +165,19 @@ public function opendir($path) {
}

public function is_dir($path) {
if ($this->caseInsensitive && !$this->file_exists($path)) {
return false;
}
if (str_ends_with($path, '/')) {
$path = substr($path, 0, -1);
}
return is_dir($this->getSourcePath($path));
}

public function is_file($path) {
if ($this->caseInsensitive && !$this->file_exists($path)) {
return false;
}
return is_file($this->getSourcePath($path));
}

Expand Down Expand Up @@ -271,7 +280,13 @@ public function isUpdatable($path) {
}

public function file_exists($path) {
return file_exists($this->getSourcePath($path));
if ($this->caseInsensitive) {
$fullPath = $this->getSourcePath($path);
$content = scandir(dirname($fullPath), SCANDIR_SORT_NONE);
return is_array($content) && array_search(basename($fullPath), $content) !== false;
} else {
return file_exists($this->getSourcePath($path));
}
}

public function filemtime($path) {
Expand Down Expand Up @@ -372,6 +387,11 @@ public function rename($source, $target): bool {
}

if (@rename($this->getSourcePath($source), $this->getSourcePath($target))) {
if ($this->caseInsensitive) {
if (mb_strtolower($target) === mb_strtolower($source) && !$this->file_exists($target)) {
return false;
}
}
return true;
}

Expand All @@ -388,6 +408,11 @@ public function copy($source, $target) {
}
$result = copy($this->getSourcePath($source), $this->getSourcePath($target));
umask($oldMask);
if ($this->caseInsensitive) {
if (mb_strtolower($target) === mb_strtolower($source) && !$this->file_exists($target)) {
return false;
}
}
return $result;
}
}
Expand Down