]> source.dussan.org Git - nextcloud-server.git/commitdiff
Introducing trait LocalTempFileTrait
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 2 Apr 2015 12:44:25 +0000 (14:44 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:30 +0000 (13:30 +0200)
lib/private/files/storage/common.php
lib/private/files/storage/localtempfiletrait.php [new file with mode: 0644]

index 9fef53fa95a0c8956e44dd9a74f36e6345f9afc2..ed85d3c07ccb5e7f0cbe031c2a5ce1cbe6803caa 100644 (file)
@@ -56,6 +56,9 @@ use OCP\Files\ReservedWordException;
  * in classes which extend it, e.g. $this->stat() .
  */
 abstract class Common implements Storage {
+
+       use LocalTempFileTrait;
+
        protected $cache;
        protected $scanner;
        protected $watcher;
@@ -63,11 +66,6 @@ abstract class Common implements Storage {
 
        protected $mountOptions = [];
 
-       /**
-        * @var string[]
-        */
-       protected $cachedFiles = array();
-
        public function __construct($parameters) {
        }
 
@@ -247,27 +245,6 @@ abstract class Common implements Storage {
                return $this->getCachedFile($path);
        }
 
-       /**
-        * @param string $path
-        * @return string
-        */
-       protected function toTmpFile($path) { //no longer in the storage api, still useful here
-               $source = $this->fopen($path, 'r');
-               if (!$source) {
-                       return false;
-               }
-               if ($pos = strrpos($path, '.')) {
-                       $extension = substr($path, $pos);
-               } else {
-                       $extension = '';
-               }
-               $tmpFile = \OC_Helper::tmpFile($extension);
-               $target = fopen($tmpFile, 'w');
-               \OC_Helper::streamCopy($source, $target);
-               fclose($target);
-               return $tmpFile;
-       }
-
        public function getLocalFolder($path) {
                $baseDir = \OC_Helper::tmpFolder();
                $this->addLocalFolder($path, $baseDir);
@@ -450,20 +427,6 @@ abstract class Common implements Storage {
                return false;
        }
 
-       /**
-        * @param string $path
-        */
-       protected function getCachedFile($path) {
-               if (!isset($this->cachedFiles[$path])) {
-                       $this->cachedFiles[$path] = $this->toTmpFile($path);
-               }
-               return $this->cachedFiles[$path];
-       }
-
-       protected function removeCachedFile($path) {
-               unset($this->cachedFiles[$path]);
-       }
-
        /**
         * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
         *
diff --git a/lib/private/files/storage/localtempfiletrait.php b/lib/private/files/storage/localtempfiletrait.php
new file mode 100644 (file)
index 0000000..444e4e2
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Files\Storage;
+
+use OC\Files\Cache\Cache;
+use OC\Files\Cache\Scanner;
+use OC\Files\Filesystem;
+use OC\Files\Cache\Watcher;
+use OCP\Files\FileNameTooLongException;
+use OCP\Files\InvalidCharacterInPathException;
+use OCP\Files\InvalidPathException;
+use OCP\Files\ReservedWordException;
+
+/**
+ * Storage backend class for providing common filesystem operation methods
+ * which are not storage-backend specific.
+ *
+ * \OC\Files\Storage\Common is never used directly; it is extended by all other
+ * storage backends, where its methods may be overridden, and additional
+ * (backend-specific) methods are defined.
+ *
+ * Some \OC\Files\Storage\Common methods call functions which are first defined
+ * in classes which extend it, e.g. $this->stat() .
+ */
+trait LocalTempFileTrait {
+
+       /**
+        * @var string[]
+        */
+       protected $cachedFiles = array();
+
+       /**
+        * @param string $path
+        */
+       protected function getCachedFile($path) {
+               if (!isset($this->cachedFiles[$path])) {
+                       $this->cachedFiles[$path] = $this->toTmpFile($path);
+               }
+               return $this->cachedFiles[$path];
+       }
+
+       protected function removeCachedFile($path) {
+               unset($this->cachedFiles[$path]);
+       }
+
+       /**
+        * @param string $path
+        * @return string
+        */
+       protected function toTmpFile($path) { //no longer in the storage api, still useful here
+               $source = $this->fopen($path, 'r');
+               if (!$source) {
+                       return false;
+               }
+               if ($pos = strrpos($path, '.')) {
+                       $extension = substr($path, $pos);
+               } else {
+                       $extension = '';
+               }
+               $tmpFile = \OC_Helper::tmpFile($extension);
+               $target = fopen($tmpFile, 'w');
+               \OC_Helper::streamCopy($source, $target);
+               fclose($target);
+               return $tmpFile;
+       }
+}