From 75b326149f0da998ef495de2a06993595476f10c 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 --- 3rdparty | 2 +- lib/private/Files/Storage/Local.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 27a56c5bb9d0e..e287243b8eeaf 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 27a56c5bb9d0ec514a8fb22044fd5f03a51ea2a5 +Subproject commit e287243b8eeaf72443b841ace3b1788e85a5aacd diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 5d0ce596b11f7..7f4568be02b71 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -274,6 +274,8 @@ public function file_get_contents($path) { } public function file_put_contents($path, $data) { + // support Write-Once-Read-Many filesystems + $this->unlink($path); return file_put_contents($this->getSourcePath($path), $data); } @@ -353,6 +355,10 @@ public function copy($path1, $path2) { } public function fopen($path, $mode) { + if ($mode === 'w') { + // support Write-Once-Read-Many filesystems + $this->unlink($path); + } return fopen($this->getSourcePath($path), $mode); }