From b6065a236fe470e37b28e768d9e09b25e92b470d Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Mon, 7 Dec 2020 18:24:37 +0100 Subject: [PATCH] files: make OC\Files\Storage\Local WORM friendly Some filesystems run as a Write-Once-Read-Many storages. This makes them impossible to use with NexeCloud, as the file system layers uses `truncate` syscall (through file_put_contents function). As Nextcloud is never updates existing files, removing the old entry and creatint a new one on update will allow NextCoud to update on such file systems. Update Local#fopen and Local#file_put_contents to remote existing file before truncating. Signed-off-by: Tigran Mkrtchyan --- lib/private/Files/Storage/Local.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 4996572a40e..7af512ca3f6 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -297,6 +297,8 @@ 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); $result = file_put_contents($this->getSourcePath($path), $data); umask($oldMask); return $result; @@ -378,6 +380,10 @@ 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 + $this->unlink($path); + } $result = fopen($this->getSourcePath($path), $mode); umask($oldMask); return $result;