summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-06-25 14:15:53 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-07-05 15:59:19 +0200
commitf2de4cb3422742e7c5c91f6bcd8c2024393bbd58 (patch)
treedab895acf38507a66306eca834133980394b6dea
parent2e56f0e2f8b653a36a811ea4669b1b36fc876f7e (diff)
downloadnextcloud-server-f2de4cb3422742e7c5c91f6bcd8c2024393bbd58.tar.gz
nextcloud-server-f2de4cb3422742e7c5c91f6bcd8c2024393bbd58.zip
some performance improvements, check for system wide mounts only once while writing share keys
-rwxr-xr-xapps/files_encryption/lib/keymanager.php65
1 files changed, 25 insertions, 40 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index e1bf59d80bf..898ea945a68 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -335,58 +335,26 @@ class Keymanager {
* @brief store share key
*
* @param \OC_FilesystemView $view
- * @param string $path relative path of the file, including filename
- * @param $userId
+ * @param string $path where the share key is stored
* @param $shareKey
- * @internal param string $key
- * @internal param string $dbClassName
* @return bool true/false
* @note The keyfile is not encrypted here. Client code must
* asymmetrically encrypt the keyfile before passing it to this method
*/
- public static function setShareKey(\OC_FilesystemView $view, $path, $userId, $shareKey) {
-
- // Here we need the currently logged in user, while userId can be a different user
- $util = new Util($view, \OCP\User::getUser());
-
- list($owner, $filename) = $util->getUidAndFilename($path);
-
- // in case of system wide mount points the keys are stored directly in the data directory
- if (self::isSystemWideMountPoint($filename)) {
- $basePath = '/files_encryption/share-keys';
- } else {
- $basePath = '/' . $owner . '/files_encryption/share-keys';
- }
-
- $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner);
-
- // try reusing key file if part file
- if (self::isPartialFilePath($shareKeyPath)) {
- $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
- } else {
- $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
- }
+ private static function setShareKey(\OC_FilesystemView $view, $path, $shareKey) {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- $result = $view->file_put_contents($writePath, $shareKey);
+ $result = $view->file_put_contents($path, $shareKey);
\OC_FileProxy::$enabled = $proxyStatus;
- if (
- is_int($result)
- && $result > 0
- ) {
-
+ if (is_int($result) && $result > 0) {
return true;
-
} else {
-
return false;
-
}
-
}
/**
@@ -400,23 +368,40 @@ class Keymanager {
// $shareKeys must be an array with the following format:
// [userId] => [encrypted key]
+ // Here we need the currently logged in user, while userId can be a different user
+ $util = new Util($view, \OCP\User::getUser());
+
+ list($owner, $filename) = $util->getUidAndFilename($path);
+
+ // in case of system wide mount points the keys are stored directly in the data directory
+ if (self::isSystemWideMountPoint($filename)) {
+ $basePath = '/files_encryption/share-keys';
+ } else {
+ $basePath = '/' . $owner . '/files_encryption/share-keys';
+ }
+
+ $shareKeyPath = self::keySetPreparation($view, $filename, $basePath, $owner);
$result = true;
foreach ($shareKeys as $userId => $shareKey) {
- if (!self::setShareKey($view, $path, $userId, $shareKey)) {
+ // try reusing key file if part file
+ if (self::isPartialFilePath($shareKeyPath)) {
+ $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
+ } else {
+ $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
+ }
+
+ if (!self::setShareKey($view, $writePath, $shareKey)) {
// If any of the keys are not set, flag false
$result = false;
-
}
-
}
// Returns false if any of the keys weren't set
return $result;
-
}
/**