$newShareKeyPath = $ownerNew . '/files_encryption/share-keys/' . $pathNew;\r
}\r
\r
- // add key ext if this is not an folder\r
+ // create new key folders if it doesn't exists\r
+ if (!$view->file_exists(dirname($newShareKeyPath))) {\r
+ $view->mkdir(dirname($newShareKeyPath));\r
+ }\r
+ if (!$view->file_exists(dirname($newKeyfilePath))) {\r
+ $view->mkdir(dirname($newKeyfilePath));\r
+ }\r
+\r
+ // handle share keys\r
if (!$view->is_dir($oldKeyfilePath)) {\r
$oldKeyfilePath .= '.key';\r
$newKeyfilePath .= '.key';\r
\r
// handle share-keys\r
- $localKeyPath = $view->getLocalFile($oldShareKeyPath);\r
- $escapedPath = Helper::escapeGlobPattern($localKeyPath);\r
- $matches = glob($escapedPath . '*.shareKey');\r
+ $matches = Helper::findShareKeys($oldShareKeyPath, $view);\r
foreach ($matches as $src) {\r
$dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));\r
-\r
- // create destination folder if not exists\r
- if (!file_exists(dirname($dst))) {\r
- mkdir(dirname($dst), 0750, true);\r
- }\r
-\r
- rename($src, $dst);\r
+ $view->rename($src, $dst);\r
}\r
\r
} else {\r
// handle share-keys folders\r
-\r
- // create destination folder if not exists\r
- if (!$view->file_exists(dirname($newShareKeyPath))) {\r
- mkdir($view->getLocalFile($newShareKeyPath), 0750, true);\r
- }\r
-\r
$view->rename($oldShareKeyPath, $newShareKeyPath);\r
}\r
\r
// Rename keyfile so it isn't orphaned\r
if ($view->file_exists($oldKeyfilePath)) {\r
-\r
- // create destination folder if not exists\r
- if (!$view->file_exists(dirname($newKeyfilePath))) {\r
- mkdir(dirname($view->getLocalFile($newKeyfilePath)), 0750, true);\r
- }\r
-\r
$view->rename($oldKeyfilePath, $newKeyfilePath);\r
}\r
\r
- // build the path to the file\r
- $newPath = '/' . $ownerNew . '/files' . $pathNew;\r
+ // update share keys\r
+ $sharingEnabled = \OCP\Share::isEnabled();\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, $pathNew);\r
+ // get users\r
+ $usersSharing = $util->getSharingUsersArray($sharingEnabled, $pathNew);\r
\r
- // update sharing-keys\r
- $util->setSharedFileKeyfiles($session, $usersSharing, $pathNew);\r
- }\r
+ // update sharing-keys\r
+ $util->setSharedFileKeyfiles($session, $usersSharing, $pathNew);\r
\r
\OC_FileProxy::$enabled = $proxyStatus;\r
}\r
return preg_replace('/(\*|\?|\[)/', '[$1]', $path);
}
+ /**
+ * find all share keys for a given file
+ * @param string $path to the file
+ * @param \OC\Files\View $view view, relative to data/
+ */
+ public static function findShareKeys($path, $view) {
+ $result = array();
+ $pathinfo = pathinfo($path);
+ $dirContent = $view->opendir($pathinfo['dirname']);
+
+ if (is_resource($dirContent)) {
+ while (($file = readdir($dirContent)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if (preg_match("/" . $pathinfo['filename'] . ".(.*).shareKey/", $file)) {
+ $result[] = $pathinfo['dirname'] . '/' . $file;
+ }
+ }
+ }
+ closedir($dirContent);
+ }
+
+ return $result;
+ }
+
/**
* remember from which file the tmp file (getLocalFile() call) was created
* @param string $tmpFile path of tmp file