diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2013-11-11 17:47:59 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2013-11-11 17:47:59 +0100 |
commit | 802213f7ecf925ff3f63c2198dde4d63fce16846 (patch) | |
tree | 4ed2f77059d5bad5fd40bf6f62d00d29b98b543a /apps/files_encryption | |
parent | 68f3f2e691a254349efb1f15953659b42ce8ad3e (diff) | |
download | nextcloud-server-802213f7ecf925ff3f63c2198dde4d63fce16846.tar.gz nextcloud-server-802213f7ecf925ff3f63c2198dde4d63fce16846.zip |
let encryption app detect transfer id in path and handle it correctly
Diffstat (limited to 'apps/files_encryption')
-rwxr-xr-x | apps/files_encryption/lib/helper.php | 27 | ||||
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 38 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 5 |
3 files changed, 34 insertions, 36 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index a754f9f28c4..98a5f1f2f28 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -158,6 +158,33 @@ class Helper { /** + * @brief Remove .path extension from a file path + * @param string $path Path that may identify a .part file + * @return string File path without .part extension + * @note this is needed for reusing keys + */ + public static function fixPartialFilePath($path) { + $extension = pathinfo($path, PATHINFO_EXTENSION); + + if ( $extension === 'part' || $extension === 'etmp') { + + $newLength = strlen($path) - 5; // 5 = strlen(".part") = strlen(".etmp") + $fPath = substr($path, 0, $newLength); + + // if path also contains a transaction id, we remove it too + $extension = pathinfo($fPath, PATHINFO_EXTENSION); + if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") + $newLength = strlen($fPath) - strlen($extension) -1; + $fPath = substr($fPath, 0, $newLength); + } + return $fPath; + + } else { + return $path; + } + } + + /** * @brief disable recovery * * @param $recoveryPassword diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 7143fcff0f6..578d8965b42 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -155,7 +155,7 @@ class Keymanager { if (self::isPartialFilePath($targetPath)) { $result = $view->file_put_contents( - $basePath . '/' . self::fixPartialFilePath($targetPath) . '.key', $catfile); + $basePath . '/' . \OCA\Encryption\Helper::fixPartialFilePath($targetPath) . '.key', $catfile); } else { @@ -170,43 +170,17 @@ class Keymanager { } /** - * @brief Remove .path extension from a file path - * @param string $path Path that may identify a .part file - * @return string File path without .part extension - * @note this is needed for reusing keys - */ - public static function fixPartialFilePath($path) { - - if (preg_match('/\.part$/', $path) || preg_match('/\.etmp$/', $path)) { - - $newLength = strlen($path) - 5; - $fPath = substr($path, 0, $newLength); - - return $fPath; - - } else { - - return $path; - - } - - } - - /** * @brief Check if a path is a .part file * @param string $path Path that may identify a .part file * @return bool */ public static function isPartialFilePath($path) { - if (preg_match('/\.part$/', $path) || preg_match('/\.etmp$/', $path)) { - + $extension = pathinfo($path, PATHINFO_EXTENSION); + if ( $extension === 'part' || $extension === 'etmp') { return true; - } else { - return false; - } } @@ -226,7 +200,7 @@ class Keymanager { $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($filePath); - $filename = self::fixPartialFilePath($filename); + $filename = \OCA\Encryption\Helper::fixPartialFilePath($filename); $filePath_f = ltrim($filename, '/'); // in case of system wide mount points the keys are stored directly in the data directory @@ -386,7 +360,7 @@ class Keymanager { // try reusing key file if part file if (self::isPartialFilePath($shareKeyPath)) { - $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; + $writePath = $basePath . '/' . \OCA\Encryption\Helper::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; } else { $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey'; } @@ -422,7 +396,7 @@ class Keymanager { $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($filePath); - $filename = self::fixPartialFilePath($filename); + $filename = \OCA\Encryption\Helper::fixPartialFilePath($filename); // in case of system wide mount points the keys are stored directly in the data directory if ($util->isSystemWideMountPoint($filename)) { $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 53d58fbf40d..9ae38a4ad8e 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1138,10 +1138,7 @@ class Util { // Make sure that a share key is generated for the owner too list($owner, $ownerPath) = $this->getUidAndFilename($filePath); - $pathinfo = pathinfo($ownerPath); - if(array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') { - $ownerPath = $pathinfo['dirname'] . '/' . $pathinfo['filename']; - } + $ownerPath = \OCA\Encryption\Helper::fixPartialFilePath($ownerPath); $userIds = array(); if ($sharingEnabled) { |