[Pkg-owncloud-commits] [owncloud] 12/145: only update file cache with the unenecrypted size when the file was written

David Prévot taffit at moszumanska.debian.org
Wed Feb 26 16:27:38 UTC 2014


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

taffit pushed a commit to branch master
in repository owncloud.

commit 33801c311ea4c950139a4f598d7868bce3a50140
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Thu Jan 23 15:45:34 2014 +0100

    only update file cache with the unenecrypted size when the file was written
---
 apps/files_encryption/lib/proxy.php | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index fc48354..5e48f8c 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -37,6 +37,7 @@ namespace OCA\Encryption;
 class Proxy extends \OC_FileProxy {
 
 	private static $blackList = null; //mimetypes blacklisted from encryption
+	private static $unencryptedSizes = array(); // remember unencrypted size
 
 	/**
 	 * Check if a file requires encryption
@@ -114,14 +115,12 @@ class Proxy extends \OC_FileProxy {
 					// get encrypted content
 					$data = $view->file_get_contents($tmpPath);
 
-					// update file cache for target file
+					// store new unenecrypted size so that it can be updated
+					// in the post proxy
 					$tmpFileInfo = $view->getFileInfo($tmpPath);
-					$fileInfo = $view->getFileInfo($path);
-					if (is_array($fileInfo) && is_array($tmpFileInfo)) {
-						$fileInfo['encrypted'] = true;
-						$fileInfo['unencrypted_size'] = $tmpFileInfo['size'];
-						$view->putFileInfo($path, $fileInfo);
-						}
+					if ( isset($tmpFileInfo['size']) ) {
+						self::$unencryptedSizes[\OC_Filesystem::normalizePath($path)] = $tmpFileInfo['size'];
+					}
 
 					// remove our temp file
 					$view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
@@ -137,6 +136,24 @@ class Proxy extends \OC_FileProxy {
 	}
 
 	/**
+	 * @brief update file cache with the new unencrypted size after file was written
+	 * @param string $path
+	 * @param mixed $result
+	 * @return mixed
+	 */
+	public function postFile_put_contents($path, $result) {
+		$normalizedPath = \OC_Filesystem::normalizePath($path);
+		if ( isset(self::$unencryptedSizes[$normalizedPath]) ) {
+			$view = new \OC_FilesystemView('/');
+			$view->putFileInfo($normalizedPath,
+					array('encrypted' => true, 'encrypted_size' => self::$unencryptedSizes[$normalizedPath]));
+			unset(self::$unencryptedSizes[$normalizedPath]);
+		}
+
+		return $result;
+	}
+
+	/**
 	 * @param string $path Path of file from which has been read
 	 * @param string $data Data that has been read from file
 	 */

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