let encryption app detect transfer id in path and handle it correctly

This commit is contained in:
Bjoern Schiessle 2013-11-11 17:47:59 +01:00
parent 68f3f2e691
commit 802213f7ec
3 changed files with 34 additions and 36 deletions

View File

@ -157,6 +157,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
*

View File

@ -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 {
@ -169,29 +169,6 @@ 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
@ -199,14 +176,11 @@ class Keymanager {
*/
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';

View File

@ -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) {