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 <tigran.mkrtchyan@desy.de>
pull/24596/head
Tigran Mkrtchyan 6 years ago
parent 9b5569ff74
commit b6065a236f
  1. 6
      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;

Loading…
Cancel
Save