Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTigran Mkrtchyan <tigran.mkrtchyan@desy.de>2022-03-31 11:38:25 +0300
committerTigran Mkrtchyan <tigran.mkrtchyan@desy.de>2022-09-16 12:10:32 +0300
commitf41209a0614a317857b77d3be80cd7ef4dbb4695 (patch)
tree8175424656aee931f899f0043ffcb6a0b810165b /lib/private
parent8fc4cf67f1553d0d37bb061925867789b27579fe (diff)
config: add a switch to control truncate before update
To avoid extra truncate on non WORM file systems, add a new config option `localstorage.unlink_on_truncate`, which defaults to false. The OC\Files\Storage\Local is update to respect that option. Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/Storage/Local.php18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php
index b9dcb7d0537..2a7e30cada6 100644
--- a/lib/private/Files/Storage/Local.php
+++ b/lib/private/Files/Storage/Local.php
@@ -69,6 +69,8 @@ class Local extends \OC\Files\Storage\Common {
private $defUMask;
+ protected bool $unlinkOnTruncate;
+
public function __construct($arguments) {
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
throw new \InvalidArgumentException('No data directory set for local storage');
@@ -88,6 +90,9 @@ class Local extends \OC\Files\Storage\Common {
$this->config = \OC::$server->get(IConfig::class);
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
$this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022);
+
+ // support Write-Once-Read-Many file systems
+ $this->unlinkOnTruncate = $this->config->getSystemValue('localstorage.unlink_on_truncate', false);
}
public function __destruct() {
@@ -297,8 +302,9 @@ class Local extends \OC\Files\Storage\Common {
public function file_put_contents($path, $data) {
$oldMask = umask($this->defUMask);
- // support Write-Once-Read-Many filesystems
- $this->unlink($path);
+ if ($this->unlinkOnTruncate) {
+ $this->unlink($path);
+ }
$result = file_put_contents($this->getSourcePath($path), $data);
umask($oldMask);
return $result;
@@ -372,8 +378,9 @@ class Local extends \OC\Files\Storage\Common {
return parent::copy($path1, $path2);
} else {
$oldMask = umask($this->defUMask);
- // support Write-Once-Read-Many filesystems
- $this->unlink($path2);
+ if ($this->unlinkOnTruncate) {
+ $this->unlink($path2);
+ }
$result = copy($this->getSourcePath($path1), $this->getSourcePath($path2));
umask($oldMask);
return $result;
@@ -382,8 +389,7 @@ class Local extends \OC\Files\Storage\Common {
public function fopen($path, $mode) {
$oldMask = umask($this->defUMask);
- if ($mode === 'w') {
- // support Write-Once-Read-Many filesystems
+ if (($mode === 'w' || $mode === 'w+') && $this->unlinkOnTruncate) {
$this->unlink($path);
}
$result = fopen($this->getSourcePath($path), $mode);