aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/files/storage/common.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/files/storage/common.php')
-rw-r--r--lib/private/files/storage/common.php27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 9e826dd6192..2b697141515 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -27,6 +27,11 @@ abstract class Common implements \OC\Files\Storage\Storage {
protected $watcher;
protected $storageCache;
+ /**
+ * @var string[]
+ */
+ protected $cachedFiles = array();
+
public function __construct($parameters) {
}
@@ -122,11 +127,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function file_put_contents($path, $data) {
$handle = $this->fopen($path, "w");
+ $this->removeCachedFile($path);
return fwrite($handle, $data);
}
public function rename($path1, $path2) {
if ($this->copy($path1, $path2)) {
+ $this->removeCachedFile($path1);
return $this->unlink($path1);
} else {
return false;
@@ -137,6 +144,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ $this->removeCachedFile($path2);
return $result;
}
@@ -152,8 +160,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function hash($type, $path, $raw = false) {
$tmpFile = $this->getLocalFile($path);
- $hash = hash($type, $tmpFile, $raw);
- unlink($tmpFile);
+ $hash = hash_file($type, $tmpFile, $raw);
return $hash;
}
@@ -162,13 +169,14 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
public function getLocalFile($path) {
- return $this->toTmpFile($path);
+ return $this->getCachedFile($path);
}
/**
* @param string $path
+ * @return string
*/
- private function toTmpFile($path) { //no longer in the storage api, still useful here
+ protected function toTmpFile($path) { //no longer in the storage api, still useful here
$source = $this->fopen($path, 'r');
if (!$source) {
return false;
@@ -352,4 +360,15 @@ abstract class Common implements \OC\Files\Storage\Storage {
// default, which is not local
return false;
}
+
+ 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]);
+ }
}