aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/lib/helper.php')
-rwxr-xr-xapps/files_encryption/lib/helper.php46
1 files changed, 31 insertions, 15 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index d427c51732f..ab19938d633 100755
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -431,24 +431,40 @@ class Helper {
/**
* find all share keys for a given file
- * @param string $path to the file
- * @param \OC\Files\View $view view, relative to data/
- * @return array list of files, path relative to data/
+ *
+ * @param string $filePath path to the file name relative to the user's files dir
+ * for example "subdir/filename.txt"
+ * @param string $shareKeyPath share key prefix path relative to the user's data dir
+ * for example "user1/files_encryption/share-keys/subdir/filename.txt"
+ * @param \OC\Files\View $rootView root view, relative to data/
+ * @return array list of share key files, path relative to data/$user
*/
- public static function findShareKeys($path, $view) {
+ public static function findShareKeys($filePath, $shareKeyPath, $rootView) {
$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;
- }
- }
+
+ $user = \OCP\User::getUser();
+ $util = new Util($rootView, $user);
+ // get current sharing state
+ $sharingEnabled = \OCP\Share::isEnabled();
+
+ // get users sharing this file
+ $usersSharing = $util->getSharingUsersArray($sharingEnabled, $filePath);
+
+ $pathinfo = pathinfo($shareKeyPath);
+
+ $baseDir = $pathinfo['dirname'] . '/';
+ $fileName = $pathinfo['basename'];
+ foreach ($usersSharing as $user) {
+ $keyName = $fileName . '.' . $user . '.shareKey';
+ if ($rootView->file_exists($baseDir . $keyName)) {
+ $result[] = $baseDir . $keyName;
+ } else {
+ \OC_Log::write(
+ 'Encryption library',
+ 'No share key found for user "' . $user . '" for file "' . $pathOld . '"',
+ \OC_Log::WARN
+ );
}
- closedir($dirContent);
}
return $result;