summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-04-02 14:44:25 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-07 13:30:30 +0200
commitd9c41b00ab4271b401ed838ccc0b19a9a0f67a76 (patch)
treea80736f66f3e175a96c8197ba11ac6fc0e57b4e4 /lib/private
parentd3e887a7cf7a0285a813fe2eddf0184e094447fd (diff)
downloadnextcloud-server-d9c41b00ab4271b401ed838ccc0b19a9a0f67a76.tar.gz
nextcloud-server-d9c41b00ab4271b401ed838ccc0b19a9a0f67a76.zip
Introducing trait LocalTempFileTrait
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/files/storage/common.php43
-rw-r--r--lib/private/files/storage/localtempfiletrait.php85
2 files changed, 88 insertions, 40 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 9fef53fa95a..ed85d3c07cc 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -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);
@@ -451,20 +428,6 @@ abstract class Common implements Storage {
}
/**
- * @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
*
* @param string $class
diff --git a/lib/private/files/storage/localtempfiletrait.php b/lib/private/files/storage/localtempfiletrait.php
new file mode 100644
index 00000000000..444e4e2e89e
--- /dev/null
+++ b/lib/private/files/storage/localtempfiletrait.php
@@ -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;
+ }
+}