From 35ab7f0e64316eba1966bde406f31885b61f15a8 Mon Sep 17 00:00:00 2001 From: Tim Dettrick Date: Mon, 10 Aug 2015 11:06:45 +1000 Subject: [PATCH] Improving fopen behaviour for Swift backend --- apps/files_external/lib/swift.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e946e7feb7..a64a02a4ed 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -354,9 +354,18 @@ class Swift extends \OC\Files\Storage\Common { } $tmpFile = \OCP\Files::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); - if ($this->file_exists($path)) { + // Fetch existing file if required + if ($mode[0] !== 'w' && $this->file_exists($path)) { + if ($mode[0] === 'x') { + // File cannot already exist + return false; + } $source = $this->fopen($path, 'r'); file_put_contents($tmpFile, $source); + // Seek to end if required + if ($mode[0] === 'a') { + fseek($tmpFile, 0, SEEK_END); + } } self::$tmpFiles[$tmpFile] = $path;