* @param array $params with the old path and the new path\r
*/\r
public static function preRename($params) {\r
- $user = \OCP\User::getUser();\r
- $view = new \OC\Files\View('/');\r
- $util = new Util($view, $user);\r
- list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']);\r
-\r
- // we only need to rename the keys if the rename happens on the same mountpoint\r
- // otherwise we perform a stream copy, so we get a new set of keys\r
- $mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']);\r
- $mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']);\r
-\r
- $type = $view->is_dir('/' . $user . '/files/' . $params['oldpath']) ? 'folder' : 'file';\r
-\r
- if ($mp1 === $mp2) {\r
- self::$renamedFiles[$params['oldpath']] = array(\r
- 'uid' => $ownerOld,\r
- 'path' => $pathOld,\r
- 'type' => $type,\r
- 'operation' => 'rename',\r
- );\r
-\r
- }\r
+ self::preRenameOrCopy($params, 'rename');\r
}\r
\r
/**\r
- * mark file as renamed so that we know the original source after the file was renamed\r
+ * mark file as copied so that we know the original source after the file was copied\r
* @param array $params with the old path and the new path\r
*/\r
public static function preCopy($params) {\r
+ self::preRenameOrCopy($params, 'copy');\r
+ }\r
+\r
+ private static function preRenameOrCopy($params, $operation) {\r
$user = \OCP\User::getUser();\r
$view = new \OC\Files\View('/');\r
$util = new Util($view, $user);\r
$type = $view->is_dir('/' . $user . '/files/' . $params['oldpath']) ? 'folder' : 'file';\r
\r
if ($mp1 === $mp2) {\r
+ if ($util->isSystemWideMountPoint($pathOld)) {\r
+ $oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;\r
+ } else {\r
+ $oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;\r
+ }\r
+ // gather share keys here because in postRename() the file will be moved already\r
+ $oldShareKeys = Helper::findShareKeys($pathOld, $oldShareKeyPath, $view);\r
+ if (count($oldShareKeys) === 0) {\r
+ \OC_Log::write(\r
+ 'Encryption library', 'No share keys found for "' . $pathOld . '"',\r
+ \OC_Log::WARN\r
+ );\r
+ }\r
self::$renamedFiles[$params['oldpath']] = array(\r
'uid' => $ownerOld,\r
'path' => $pathOld,\r
'type' => $type,\r
- 'operation' => 'copy');\r
+ 'operation' => $operation,\r
+ 'sharekeys' => $oldShareKeys\r
+ );\r
+\r
}\r
}\r
\r
$view = new \OC\Files\View('/');\r
$userId = \OCP\User::getUser();\r
$util = new Util($view, $userId);\r
+ $oldShareKeys = null;\r
\r
if (isset(self::$renamedFiles[$params['oldpath']]['uid']) &&\r
isset(self::$renamedFiles[$params['oldpath']]['path'])) {\r
$pathOld = self::$renamedFiles[$params['oldpath']]['path'];\r
$type = self::$renamedFiles[$params['oldpath']]['type'];\r
$operation = self::$renamedFiles[$params['oldpath']]['operation'];\r
+ $oldShareKeys = self::$renamedFiles[$params['oldpath']]['sharekeys'];\r
unset(self::$renamedFiles[$params['oldpath']]);\r
} else {\r
\OCP\Util::writeLog('Encryption library', "can't get path and owner from the file before it was renamed", \OCP\Util::DEBUG);\r
$oldKeyfilePath .= '.key';\r
$newKeyfilePath .= '.key';\r
\r
- // handle share-keys\r
- $matches = Helper::findShareKeys($pathOld, $oldShareKeyPath, $view);\r
- if (count($matches) === 0) {\r
- \OC_Log::write(\r
- 'Encryption library', 'No share keys found for "' . $pathOld . '"',\r
- \OC_Log::WARN\r
- );\r
- }\r
- foreach ($matches as $src) {\r
+ foreach ($oldShareKeys as $src) {\r
$dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));\r
$view->$operation($src, $dst);\r
}\r