summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-01-29 16:33:27 +0100
committerRobin Appelman <icewind@owncloud.com>2014-01-29 16:33:27 +0100
commit4e2b52a376d2aab5e0f9d0034a8e2bfa196c08bd (patch)
tree78094fbe60703eae8e4eb1d5d7a42d249a515f21 /apps/files_encryption/lib
parentfc5f20112efe03b203978c4b1045ed70c2ce5e74 (diff)
parentf5f918b8bf5279fd174fe520c21f83c902904843 (diff)
downloadnextcloud-server-4e2b52a376d2aab5e0f9d0034a8e2bfa196c08bd.tar.gz
nextcloud-server-4e2b52a376d2aab5e0f9d0034a8e2bfa196c08bd.zip
merge master into fileinfo
Diffstat (limited to 'apps/files_encryption/lib')
-rw-r--r--apps/files_encryption/lib/proxy.php31
-rw-r--r--apps/files_encryption/lib/util.php52
2 files changed, 37 insertions, 46 deletions
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 0b7e066f2e2..9dd7b979390 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 ($fileInfo && $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
*/
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 8a5dfabeec1..8816d4d649a 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -2,9 +2,10 @@
/**
* ownCloud
*
- * @author Sam Tuke, Frank Karlitschek
+ * @author Sam Tuke, Frank Karlitschek, Bjoern Schiessle
* @copyright 2012 Sam Tuke <samtuke@owncloud.com>,
- * Frank Karlitschek <frank@owncloud.org>
+ * Frank Karlitschek <frank@owncloud.org>,
+ * Bjoern Schiessle <schiessle@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -1360,59 +1361,32 @@ class Util {
}
}
-
/**
* @brief go recursively through a dir and collect all files and sub files.
* @param string $dir relative to the users files folder
* @return array with list of files relative to the users files folder
*/
public function getAllFiles($dir) {
-
$result = array();
+ $dirList = array($dir);
- $content = $this->view->getDirectoryContent(\OC\Files\Filesystem::normalizePath(
- $this->userFilesDir . '/' . $dir));
-
- // handling for re shared folders
- $pathSplit = explode('/', $dir);
-
- foreach ($content as $c) {
-
- $sharedPart = $pathSplit[sizeof($pathSplit) - 1];
- $targetPathSplit = array_reverse(explode('/', $c['path']));
-
- $path = '';
-
- // rebuild path
- foreach ($targetPathSplit as $pathPart) {
-
- if ($pathPart !== $sharedPart) {
-
- $path = '/' . $pathPart . $path;
+ while ($dirList) {
+ $dir = array_pop($dirList);
+ $content = $this->view->getDirectoryContent(\OC\Files\Filesystem::normalizePath(
+ $this->userFilesDir . '/' . $dir));
+ foreach ($content as $c) {
+ $usersPath = isset($c['usersPath']) ? $c['usersPath'] : $c['path'];
+ if ($c['type'] === 'dir') {
+ $dirList[] = substr($usersPath, strlen("files"));
} else {
-
- break;
-
+ $result[] = substr($usersPath, strlen("files"));
}
-
}
- $path = $dir . $path;
-
- if ($c['type'] === 'dir') {
-
- $result = array_merge($result, $this->getAllFiles($path));
-
- } else {
-
- $result[] = $path;
-
- }
}
return $result;
-
}
/**