[Pkg-owncloud-commits] [owncloud] 81/123: delete all file keys doesn't need the encryption module as parameter; implement rmdir; getFileKeyDir should also work for part files and complete directories

David Prévot taffit at moszumanska.debian.org
Tue May 19 23:55:19 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 ccbefb6e7506f5ad7cc23c9ae50971f8ea18b463
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Wed May 13 14:39:27 2015 +0200

    delete all file keys doesn't need the encryption module as parameter; implement rmdir; getFileKeyDir should also work for part files and complete directories
---
 apps/encryption/lib/keymanager.php               |  2 +-
 lib/private/encryption/keys/storage.php          | 14 +++---------
 lib/private/files/storage/wrapper/encryption.php | 27 ++++++++++++++++++++----
 lib/public/encryption/keys/istorage.php          |  3 +--
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php
index aa96148..05d2387 100644
--- a/apps/encryption/lib/keymanager.php
+++ b/apps/encryption/lib/keymanager.php
@@ -483,7 +483,7 @@ class KeyManager {
 	}
 
 	public function deleteAllFileKeys($path) {
-		return $this->keyStorage->deleteAllFileKeys($path, Encryption::ID);
+		return $this->keyStorage->deleteAllFileKeys($path);
 	}
 
 	/**
diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php
index 118c8dc..6aa00c5 100644
--- a/lib/private/encryption/keys/storage.php
+++ b/lib/private/encryption/keys/storage.php
@@ -125,10 +125,9 @@ class Storage implements IStorage {
 	/**
 	 * @inheritdoc
 	 */
-	public function deleteAllFileKeys($path, $encryptionModuleId) {
-		$keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
-		$path = dirname($keyDir);
-		return !$this->view->file_exists($path) || $this->view->deleteAll($path);
+	public function deleteAllFileKeys($path) {
+		$keyDir = $this->getFileKeyDir('', $path);
+		return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir);
 	}
 
 	/**
@@ -208,17 +207,10 @@ class Storage implements IStorage {
 	 * @param string $encryptionModuleId
 	 * @param string $path path to the file, relative to data/
 	 * @return string
-	 * @throws GenericEncryptionException
-	 * @internal param string $keyId
 	 */
 	private function getFileKeyDir($encryptionModuleId, $path) {
 
-		if ($this->view->is_dir($path)) {
-			throw new GenericEncryptionException("file was expected but directory was given: $path");
-		}
-
 		list($owner, $filename) = $this->util->getUidAndFilename($path);
-		$filename = $this->util->stripPartialFileExtension($filename);
 
 		// in case of system wide mount points the keys are stored directly in the data directory
 		if ($this->util->isSystemWideMountPoint($filename, $owner)) {
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index c42e6d4..f7759d9 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -206,8 +206,7 @@ class Encryption extends Wrapper {
 
 		$encryptionModule = $this->getEncryptionModule($path);
 		if ($encryptionModule) {
-			$this->keyStorage->deleteAllFileKeys($this->getFullPath($path),
-				$encryptionModule->getId());
+			$this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
 		}
 
 		return $this->storage->unlink($path);
@@ -239,6 +238,21 @@ class Encryption extends Wrapper {
 	}
 
 	/**
+	 * see http://php.net/manual/en/function.rmdir.php
+	 *
+	 * @param string $path
+	 * @return bool
+	 */
+	public function rmdir($path) {
+		$result = $this->storage->rmdir($path);
+		if ($result && $this->encryptionManager->isEnabled()) {
+			$this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
+		}
+
+		return $result;
+	}
+
+	/**
 	 * see http://php.net/manual/en/function.copy.php
 	 *
 	 * @param string $path1
@@ -269,8 +283,13 @@ class Encryption extends Wrapper {
 				}
 			}
 			$data = $this->getMetaData($path1);
-			$this->getCache()->put($path2, ['encrypted' => $data['encrypted']]);
-			$this->updateUnencryptedSize($fullPath2, $data['size']);
+
+			if (isset($data['encrypted'])) {
+				$this->getCache()->put($path2, ['encrypted' => $data['encrypted']]);
+			}
+			if (isset($data['size'])) {
+				$this->updateUnencryptedSize($fullPath2, $data['size']);
+			}
 		}
 
 		return $result;
diff --git a/lib/public/encryption/keys/istorage.php b/lib/public/encryption/keys/istorage.php
index 752c073..1767781 100644
--- a/lib/public/encryption/keys/istorage.php
+++ b/lib/public/encryption/keys/istorage.php
@@ -129,12 +129,11 @@ interface IStorage {
 	 * delete all file keys for a given file
 	 *
 	 * @param string $path to the file
-	 * @param string $encryptionModuleId
 	 *
 	 * @return boolean False when the keys could not be deleted
 	 * @since 8.1.0
 	 */
-	public function deleteAllFileKeys($path, $encryptionModuleId);
+	public function deleteAllFileKeys($path);
 
 	/**
 	 * delete system-wide encryption keys not related to a specific user,

-- 
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