[Pkg-owncloud-commits] [owncloud] 99/122: update 'encrypted'-flag in file cache according to the storage settings

David Prévot taffit at moszumanska.debian.org
Sat May 9 00:00:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit e4829a23585069aaed7260ad69c041c1848b0342
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Thu Apr 30 14:30:02 2015 +0200

    update 'encrypted'-flag in file cache according to the storage settings
---
 lib/private/files/storage/common.php             |  5 +++
 lib/private/files/storage/wrapper/encryption.php | 48 +++++++++++++++++++++---
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 06c61fe..fc30b38 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 c37d3b4..c2a29bd 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list