Skip to content

Commit

Permalink
files: make OC\Files\Storage\Local WORM friendly
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kofemann committed Jan 28, 2022
1 parent 4d98612 commit 44e2a7d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public function file_get_contents($path) {

public function file_put_contents($path, $data) {
$oldMask = umask(022);
// support Write-Once-Read-Many filesystems
$this->unlink($path);
$result = file_put_contents($this->getSourcePath($path), $data);
umask($oldMask);
return $result;
Expand Down Expand Up @@ -360,6 +362,10 @@ public function copy($path1, $path2) {

public function fopen($path, $mode) {
$oldMask = umask(022);
if ($mode === 'w') {
// support Write-Once-Read-Many filesystems
$this->unlink($path);
}
$result = fopen($this->getSourcePath($path), $mode);
umask($oldMask);
return $result;
Expand Down

0 comments on commit 44e2a7d

Please sign in to comment.