diff options
-rw-r--r-- | apps/files_encryption/hooks/hooks.php | 127 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 101 | ||||
-rw-r--r-- | apps/files_sharing/lib/cache.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/tests/cache.php | 18 | ||||
-rw-r--r-- | lib/private/share/share.php | 1 |
5 files changed, 33 insertions, 219 deletions
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 7a8b54e2d75..5f0494e62ca 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -302,25 +302,6 @@ class Hooks { */
public static function postShared($params) {
- // NOTE: $params has keys:
- // [itemType] => file
- // itemSource -> int, filecache file ID
- // [parent] =>
- // [itemTarget] => /13
- // shareWith -> string, uid of user being shared to
- // fileTarget -> path of file being shared
- // uidOwner -> owner of the original file being shared
- // [shareType] => 0
- // [shareWith] => test1
- // [uidOwner] => admin
- // [permissions] => 17
- // [fileSource] => 13
- // [fileTarget] => /test8
- // [id] => 10
- // [token] =>
- // [run] => whether emitting script should continue to run
- // TODO: Should other kinds of item be encrypted too?
-
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
@@ -331,68 +312,22 @@ class Hooks { $session = new \OCA\Encryption\Session($view);
$userId = \OCP\User::getUser();
$util = new Util($view, $userId);
- $path = $util->fileIdToPath($params['itemSource']);
-
- $share = $util->getParentFromShare($params['id']);
- //if parent is set, then this is a re-share action
- if ($share['parent'] !== null) {
-
- // get the parent from current share
- $parent = $util->getShareParent($params['parent']);
-
- // if parent has the same type than the child it is a 1:1 share
- if ($parent['item_type'] === $params['itemType']) {
- $path = $parent['file_target'];
- } else {
-
- // NOTE: parent is folder but shared was a file!
- // we try to rebuild the missing path
- // some examples we face here
- // user1 share folder1 with user2 folder1 has
- // the following structure
- // /folder1/subfolder1/subsubfolder1/somefile.txt
- // user2 re-share subfolder2 with user3
- // user3 re-share somefile.txt user4
- // so our path should be
- // /Shared/subfolder1/subsubfolder1/somefile.txt
- // while user3 is sharing
-
- if ($params['itemType'] === 'file') {
- // get target path
- $targetPath = $util->fileIdToPath($params['fileSource']);
- $targetPathSplit = array_reverse(explode('/', $targetPath));
-
- // init values
- $path = '';
- $sharedPart = ltrim($parent['file_target'], '/');
-
- // rebuild path
- foreach ($targetPathSplit as $pathPart) {
- if ($pathPart !== $sharedPart) {
- $path = '/' . $pathPart . $path;
- } else {
- break;
- }
- }
- $path = $parent['file_target'] . $path;
- } else {
- $path = $parent['file_target'] . $params['fileTarget'];
- }
- }
- }
+ $path = \OC\Files\Filesystem::getPath($params['fileSource']);
$sharingEnabled = \OCP\Share::isEnabled();
// get the path including mount point only if not a shared folder
list($storage, ) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/files' . $path);
- if (!($storage instanceof \OC\Files\Storage\Shared)) {
- // get path including the the storage mount point
- $path = $util->getPathWithMountPoint($params['itemSource']);
+
+ if (!($storage instanceof \OC\Files\Storage\Local)) {
+ $mountPoint = 'files' . $storage->getMountPoint();
+ } else {
+ $mountPoint = '';
}
// if a folder was shared, get a list of all (sub-)folders
if ($params['itemType'] === 'folder') {
- $allFiles = $util->getAllFiles($path);
+ $allFiles = $util->getAllFiles($path, $mountPoint);
} else {
$allFiles = array($path);
}
@@ -409,13 +344,6 @@ class Hooks { */
public static function postUnshare($params) {
- // NOTE: $params has keys:
- // [itemType] => file
- // [itemSource] => 13
- // [shareType] => 0
- // [shareWith] => test1
- // [itemParent] =>
-
if (\OCP\App::isEnabled('files_encryption') === false) {
return true;
}
@@ -425,34 +353,7 @@ class Hooks { $view = new \OC_FilesystemView('/');
$userId = \OCP\User::getUser();
$util = new Util($view, $userId);
- $path = $util->fileIdToPath($params['itemSource']);
-
- // check if this is a re-share
- if ($params['itemParent']) {
-
- // get the parent from current share
- $parent = $util->getShareParent($params['itemParent']);
-
- // get target path
- $targetPath = $util->fileIdToPath($params['itemSource']);
- $targetPathSplit = array_reverse(explode('/', $targetPath));
-
- // init values
- $path = '';
- $sharedPart = ltrim($parent['file_target'], '/');
-
- // rebuild path
- foreach ($targetPathSplit as $pathPart) {
- if ($pathPart !== $sharedPart) {
- $path = '/' . $pathPart . $path;
- } else {
- break;
- }
- }
-
- // prefix path with Shared
- $path = $parent['file_target'] . $path;
- }
+ $path = \OC\Files\Filesystem::getPath($params['fileSource']);
// for group shares get a list of the group members
if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
@@ -466,15 +367,17 @@ class Hooks { }
// get the path including mount point only if not a shared folder
- list($storage, ) = \OC\Files\Filesystem::resolvePath($path);
- if (!($storage instanceof \OC\Files\Storage\Shared)) {
- // get path including the the storage mount point
- //$path = $util->getPathWithMountPoint($params['itemSource']);
+ list($storage, ) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/files' . $path);
+
+ if (!($storage instanceof \OC\Files\Storage\Local)) {
+ $mountPoint = 'files' . $storage->getMountPoint();
+ } else {
+ $mountPoint = '';
}
// if we unshare a folder we need a list of all (sub-)files
if ($params['itemType'] === 'folder') {
- $allFiles = $util->getAllFiles($path);
+ $allFiles = $util->getAllFiles($path, $mountPoint);
} else {
$allFiles = array($path);
}
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 4be4ab95653..6372ab31b6e 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -970,33 +970,6 @@ class Util { } /** - * @brief get path of a file. - * @param int $fileId id of the file - * @return string path of the file - */ - public static function fileIdToPath($fileId) { - - $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; - - $query = \OCP\DB::prepare($sql); - - $result = $query->execute(array($fileId)); - - $path = false; - if (\OCP\DB::isError($result)) { - \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); - } else { - $row = $result->fetchRow(); - if ($row) { - $path = substr($row['path'], strlen('files')); - } - } - - return $path; - - } - - /** * @brief Filter an array of UIDs to return only ones ready for sharing * @param array $unfilteredUsers users to be checked for sharing readiness * @return array as multi-dimensional array. keys: ready, unready @@ -1398,7 +1371,7 @@ class Util { * @param string $dir relative to the users files folder * @return array with list of files relative to the users files folder */ - public function getAllFiles($dir) { + public function getAllFiles($dir, $mountPoint = '') { $result = array(); $dirList = array($dir); @@ -1408,10 +1381,13 @@ class Util { $this->userFilesDir . '/' . $dir)); foreach ($content as $c) { + // getDirectoryContent() returns the paths relative to the mount points, so we need + // to re-construct the complete path + $path = ($mountPoint !== '') ? $mountPoint . '/' . $c['path'] : $c['path']; if ($c['type'] === 'dir') { - $dirList[] = substr($c['path'], strlen("files")); + $dirList[] = substr($path, strlen("files")); } else { - $result[] = substr($c['path'], strlen("files")); + $result[] = substr($path, strlen("files")); } } @@ -1421,54 +1397,6 @@ class Util { } /** - * @brief get shares parent. - * @param int $id of the current share - * @return array of the parent - */ - public static function getShareParent($id) { - - $sql = 'SELECT `file_target`, `item_type` FROM `*PREFIX*share` WHERE `id` = ?'; - - $query = \OCP\DB::prepare($sql); - - $result = $query->execute(array($id)); - - $row = array(); - if (\OCP\DB::isError($result)) { - \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); - } else { - $row = $result->fetchRow(); - } - - return $row; - - } - - /** - * @brief get shares parent. - * @param int $id of the current share - * @return array of the parent - */ - public static function getParentFromShare($id) { - - $sql = 'SELECT `parent` FROM `*PREFIX*share` WHERE `id` = ?'; - - $query = \OCP\DB::prepare($sql); - - $result = $query->execute(array($id)); - - $row = array(); - if (\OCP\DB::isError($result)) { - \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); - } else { - $row = $result->fetchRow(); - } - - return $row; - - } - - /** * @brief get owner of the shared files. * @param $id * @internal param int $Id of a share @@ -1710,23 +1638,6 @@ class Util { } /** - * Get the path including the storage mount point - * @param int $id - * @return string the path including the mount point like AmazonS3/folder/file.txt - */ - public function getPathWithMountPoint($id) { - list($storage, $internalPath) = \OC\Files\Cache\Cache::getById($id); - $mount = \OC\Files\Filesystem::getMountByStorageId($storage); - $mountPoint = $mount[0]->getMountPoint(); - $path = \OC\Files\Filesystem::normalizePath($mountPoint . '/' . $internalPath); - - // reformat the path to be relative e.g. /user/files/folder becomes /folder/ - $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path); - - return $relativePath; - } - - /** * @brief check if the file is stored on a system wide mount point * @param $path relative to /data/user with leading '/' * @return boolean diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 3d9fbcf4de9..4b473c60577 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -141,15 +141,14 @@ class Shared_Cache extends Cache { $folder = ''; } - $dir = 'files' . $this->storage->getMountPoint(); - $dir .= ($folder !== '') ? '/' . $folder : ''; + $dir = ($folder !== '') ? $folder . '/' : ''; $cache = $this->getSourceCache($folder); if ($cache) { $parent = $this->storage->getFile($folder); $sourceFolderContent = $cache->getFolderContents($this->files[$folder]); foreach ($sourceFolderContent as $key => $c) { - $sourceFolderContent[$key]['path'] = $dir . '/' . $c['name']; + $sourceFolderContent[$key]['path'] = $dir . $c['name']; $sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner']; $sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner']; } diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php index b8ebeab3c39..1af73c558d5 100644 --- a/apps/files_sharing/tests/cache.php +++ b/apps/files_sharing/tests/cache.php @@ -100,15 +100,15 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { $check = array( array( 'name' => 'bar.txt', - 'path' => 'files/shareddir/bar.txt' + 'path' => 'bar.txt' ), array( 'name' => 'another too.txt', - 'path' => 'files/shareddir/subdir/another too.txt' + 'path' => 'subdir/another too.txt' ), array( 'name' => 'another.txt', - 'path' => 'files/shareddir/subdir/another.txt' + 'path' => 'subdir/another.txt' ), ); $this->verifyFiles($check, $results); @@ -151,17 +151,17 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { array( array( 'name' => 'bar.txt', - 'path' => 'files/shareddir/bar.txt', + 'path' => 'bar.txt', 'mimetype' => 'text/plain', ), array( 'name' => 'emptydir', - 'path' => 'files/shareddir/emptydir', + 'path' => 'emptydir', 'mimetype' => 'httpd/unix-directory', ), array( 'name' => 'subdir', - 'path' => 'files/shareddir/subdir', + 'path' => 'subdir', 'mimetype' => 'httpd/unix-directory', ), ), @@ -185,17 +185,17 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { array( array( 'name' => 'another too.txt', - 'path' => 'files/subdir/another too.txt', + 'path' => 'another too.txt', 'mimetype' => 'text/plain', ), array( 'name' => 'another.txt', - 'path' => 'files/subdir/another.txt', + 'path' => 'another.txt', 'mimetype' => 'text/plain', ), array( 'name' => 'not a text file.xml', - 'path' => 'files/subdir/not a text file.xml', + 'path' => 'not a text file.xml', 'mimetype' => 'application/xml', ), ), diff --git a/lib/private/share/share.php b/lib/private/share/share.php index c07dd04b29f..4e3e261baf5 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -896,6 +896,7 @@ class Share extends \OC\Share\Constants { $hookParams = array( 'itemType' => $item['item_type'], 'itemSource' => $item['item_source'], + 'fileSource' => $item['file_source'], 'shareType' => $item['share_type'], 'shareWith' => $item['share_with'], 'itemParent' => $item['parent'], |