]> source.dussan.org Git - nextcloud-server.git/commitdiff
Improving fopen behaviour for Swift backend
authorTim Dettrick <t.dettrick@uq.edu.au>
Mon, 10 Aug 2015 01:06:45 +0000 (11:06 +1000)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 7 Dec 2015 09:20:09 +0000 (10:20 +0100)
apps/files_external/lib/swift.php

index e946e7feb77ae91079b58bf2b178548f77759398..a64a02a4ed9fe589c4003e49025d1167e3b9abdf 100644 (file)
@@ -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;