diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-04-15 20:18:04 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-04-23 12:54:26 +0200 |
commit | fb88aba8f4927b3175df34a2a499978a3b4c1b6b (patch) | |
tree | f05caeb3b23835730509102d5975312c425ec7a5 /apps/files_encryption | |
parent | d468cdacf27acf1de78a7b2f07d21d1851aa8f39 (diff) | |
download | nextcloud-server-fb88aba8f4927b3175df34a2a499978a3b4c1b6b.tar.gz nextcloud-server-fb88aba8f4927b3175df34a2a499978a3b4c1b6b.zip |
some fixes to make the gallery work, this made it necessary to adjust some tests and the encryption code
Diffstat (limited to 'apps/files_encryption')
-rw-r--r-- | apps/files_encryption/hooks/hooks.php | 127 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 101 |
2 files changed, 21 insertions, 207 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 |