summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-04-30 14:30:02 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-05-06 14:20:05 +0200
commite4829a23585069aaed7260ad69c041c1848b0342 (patch)
treef1be709653f92f2b8fa2f6454fd283a9518a455c
parentdc39bda8704d54d7481b9b42d2cea44146d18a3d (diff)
downloadnextcloud-server-e4829a23585069aaed7260ad69c041c1848b0342.tar.gz
nextcloud-server-e4829a23585069aaed7260ad69c041c1848b0342.zip
update 'encrypted'-flag in file cache according to the storage settings
-rw-r--r--lib/private/files/storage/common.php5
-rw-r--r--lib/private/files/storage/wrapper/encryption.php48
2 files changed, 47 insertions, 6 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 06c61fe6931..fc30b385e2e 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -545,6 +545,11 @@ abstract class Common implements Storage {
}
} else {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
+ // TODO: call fopen in a way that we execute again all storage wrappers
+ // to avoid that we bypass storage wrappers which perform important actions
+ // for this operation. Same is true for all other operations which
+ // are not the same as the original one.Once this is fixed we also
+ // need to adjust the encryption wrapper.
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
if ($result and $preserveMtime) {
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index c37d3b43471..c2a29bdb0ce 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -373,8 +373,14 @@ class Encryption extends Wrapper {
* @param bool $preserveMtime
* @return bool
*/
- public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
- $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true);
+ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true) {
+
+ // TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed:
+ // - call $this->storage->moveFromStorage() instead of $this->copyBetweenStorage
+ // - copy the file cache update from $this->copyBetweenStorage to this method
+ // - remove $this->copyBetweenStorage
+
+ $result = $this->copyBetweenStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, true);
if ($result) {
if ($sourceStorage->is_dir($sourceInternalPath)) {
$result &= $sourceStorage->rmdir($sourceInternalPath);
@@ -394,6 +400,26 @@ class Encryption extends Wrapper {
* @return bool
*/
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
+
+ // TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed:
+ // - call $this->storage->moveFromStorage() instead of $this->copyBetweenStorage
+ // - copy the file cache update from $this->copyBetweenStorage to this method
+ // - remove $this->copyBetweenStorage
+
+ return $this->copyBetweenStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, false);
+ }
+
+ /**
+ * copy file between two storages
+ *
+ * @param \OCP\Files\Storage $sourceStorage
+ * @param $sourceInternalPath
+ * @param $targetInternalPath
+ * @param $preserveMtime
+ * @param $isRename
+ * @return bool
+ */
+ private function copyBetweenStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
if ($sourceStorage->is_dir($sourceInternalPath)) {
$dh = $sourceStorage->opendir($sourceInternalPath);
$result = $this->mkdir($targetInternalPath);
@@ -408,13 +434,23 @@ class Encryption extends Wrapper {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
- if ($result and $preserveMtime) {
- $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
- }
fclose($source);
fclose($target);
- if (!$result) {
+ if($result) {
+ if ($preserveMtime) {
+ $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
+ }
+ $isEncrypted = $this->mount->getOption('encrypt', true) ? 1 : 0;
+
+ // in case of a rename we need to manipulate the source cache because
+ // this information will be kept for the new target
+ if ($isRename) {
+ $sourceStorage->getCache()->put($sourceInternalPath, ['encrypted' => $isEncrypted]);
+ } else {
+ $this->getCache()->put($targetInternalPath, ['encrypted' => $isEncrypted]);
+ }
+ } else {
// delete partially written target file
$this->unlink($targetInternalPath);
// delete cache entry that was created by fopen