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
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-09-16 15:39:13 +0300
committerGitHub <noreply@github.com>2022-09-16 15:39:13 +0300
commit1025d049c770e0512cc4074d60ed1486668a888e (patch)
tree8d23e01d4639156845f6d22514c174f3bb6ecce3 /lib
parentb3ca186d2ddaea953d7fec53055947428183b1fd (diff)
parentf41209a0614a317857b77d3be80cd7ef4dbb4695 (diff)
Merge pull request #24596 from kofemann/dcache-worm
make NextCloud WORM file system friendly
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Storage/Local.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php
index 4996572a40e..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,6 +302,9 @@ class Local extends \OC\Files\Storage\Common {
public function file_put_contents($path, $data) {
$oldMask = umask($this->defUMask);
+ if ($this->unlinkOnTruncate) {
+ $this->unlink($path);
+ }
$result = file_put_contents($this->getSourcePath($path), $data);
umask($oldMask);
return $result;
@@ -370,6 +378,9 @@ class Local extends \OC\Files\Storage\Common {
return parent::copy($path1, $path2);
} else {
$oldMask = umask($this->defUMask);
+ if ($this->unlinkOnTruncate) {
+ $this->unlink($path2);
+ }
$result = copy($this->getSourcePath($path1), $this->getSourcePath($path2));
umask($oldMask);
return $result;
@@ -378,6 +389,9 @@ class Local extends \OC\Files\Storage\Common {
public function fopen($path, $mode) {
$oldMask = umask($this->defUMask);
+ if (($mode === 'w' || $mode === 'w+') && $this->unlinkOnTruncate) {
+ $this->unlink($path);
+ }
$result = fopen($this->getSourcePath($path), $mode);
umask($oldMask);
return $result;