// we may not need to implement it\r
\r
}\r
- \r
+\r
+\r
+ /**\r
+ * @brief after a file is renamed, rename its keyfile and share-keys also fix the file size and fix also the sharing\r
+ * @param array with oldpath and newpath\r
+ *\r
+ * This function is connected to the rename signal of OC_Filesystem and adjust the name and location\r
+ * of the stored versions along the actual file\r
+ */\r
+ public static function postRename($params) {\r
+ // Disable encryption proxy to prevent recursive calls\r
+ $proxyStatus = \OC_FileProxy::$enabled;\r
+ \OC_FileProxy::$enabled = false;\r
+\r
+ $view = new \OC_FilesystemView('/');\r
+ $session = new Session($view);\r
+ $userId = \OCP\User::getUser();\r
+ $util = new Util( $view, $userId );\r
+\r
+ // Format paths to be relative to user files dir\r
+ $oldKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath'];\r
+ $newKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath'];\r
+\r
+ // add key ext if this is not an folder\r
+ if (!$view->is_dir($oldKeyfilePath)) {\r
+ $oldKeyfilePath .= '.key';\r
+ $newKeyfilePath .= '.key';\r
+\r
+ // handle share-keys\r
+ $localKeyPath = $view->getLocalFile($userId.'/files_encryption/share-keys/'.$params['oldpath']);\r
+ $matches = glob(preg_quote($localKeyPath).'*.shareKey');\r
+ foreach ($matches as $src) {\r
+ $dst = str_replace($params['oldpath'], $params['newpath'], $src);\r
+ rename($src, $dst);\r
+ }\r
+\r
+ } else {\r
+ // handle share-keys folders\r
+ $oldShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath'];\r
+ $newShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath'];\r
+ $view->rename($oldShareKeyfilePath, $newShareKeyfilePath);\r
+ }\r
+\r
+ // Rename keyfile so it isn't orphaned\r
+ if($view->file_exists($oldKeyfilePath)) {\r
+ $view->rename($oldKeyfilePath, $newKeyfilePath);\r
+ }\r
+\r
+ // build the path to the file\r
+ $newPath = '/' . $userId . '/files' .$params['newpath'];\r
+ $newPathRelative = $params['newpath'];\r
+\r
+ if($util->fixFileSize($newPath)) {\r
+ // get sharing app state\r
+ $sharingEnabled = \OCP\Share::isEnabled();\r
+\r
+ // get users\r
+ $usersSharing = $util->getSharingUsersArray($sharingEnabled, $newPathRelative);\r
+\r
+ // update sharing-keys\r
+ $util->setSharedFileKeyfiles($session, $usersSharing, $newPathRelative);\r
+ }\r
+\r
+ \OC_FileProxy::$enabled = $proxyStatus;\r
+ }\r
}\r