summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_encryption/hooks/hooks.php17
-rw-r--r--apps/files_encryption/lib/util.php26
-rwxr-xr-xapps/files_encryption/tests/webdav.php2
-rw-r--r--lib/public/share.php84
4 files changed, 87 insertions, 42 deletions
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 955425595ba..9893cecc94e 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -329,6 +329,13 @@ class Hooks {
// if a folder was shared, get a list of all (sub-)folders
if ($params['itemType'] === 'folder') {
+
+ // get the path including mount point only if not a shared folder
+ if(strncmp($path, '/Shared' , strlen('/Shared') !== 0)) {
+ // get path including the the storage mount point
+ $path = $util->getPathWithMountPoint($params['itemSource']);
+ }
+
$allFiles = $util->getAllFiles($path);
} else {
$allFiles = array($path);
@@ -405,10 +412,16 @@ class Hooks {
}
// if we unshare a folder we need a list of all (sub-)files
- if ($params['itemType'] === 'folder') {
+ if ( $params['itemType'] === 'folder' ) {
- $allFiles = $util->getAllFiles($path);
+ // get the path including mount point only if not a shared folder
+ if(strncmp($path, '/Shared' , strlen('/Shared') !== 0)) {
+ // get path including the the storage mount point
+ $path = $util->getPathWithMountPoint($params['itemSource']);
+ }
+ $allFiles = $util->getAllFiles( $path );
+
} else {
$allFiles = array($path);
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 0d663549bf6..0c1421a471b 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -541,7 +541,7 @@ class Util {
// we only need 24 byte from the last chunk
$data = '';
$handle = $this->view->fopen($path, 'r');
- if (!fseek($handle, -24, SEEK_END)) {
+ if (is_resource($handle) && !fseek($handle, -24, SEEK_END)) {
$data = fgets($handle);
}
@@ -1028,7 +1028,7 @@ class Util {
if ($sharingEnabled) {
// Find out who, if anyone, is sharing the file
- $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, true, true, true);
+ $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, true);
$userIds = $result['users'];
if ($result['public']) {
$userIds[] = $this->publicShareKeyId;
@@ -1199,7 +1199,7 @@ class Util {
$result = array();
- $content = $this->view->getDirectoryContent($this->userFilesDir . $dir);
+ $content = $this->view->getDirectoryContent(\OC\Files\Filesystem::normalizePath($this->userFilesDir . '/' . $dir));
// handling for re shared folders
$path_split = explode('/', $dir);
@@ -1459,7 +1459,7 @@ class Util {
// Find out who, if anyone, is sharing the file
if ($sharingEnabled) {
- $result = \OCP\Share::getUsersSharingFile($file, $this->userId, true, true, true);
+ $result = \OCP\Share::getUsersSharingFile($file, $this->userId, true);
$userIds = $result['users'];
$userIds[] = $this->recoveryKeyId;
if ($result['public']) {
@@ -1535,4 +1535,22 @@ class Util {
$this->recoverAllFiles('/', $privateKey);
}
+ /**
+ * 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/
+ $pathSplit = explode( '/', $path );
+ $relativePath = implode( '/', array_slice( $pathSplit, 3 ) );
+
+ return $relativePath;
+ }
+
}
diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php
index 0b3bed93e1f..1d406789f0c 100755
--- a/apps/files_encryption/tests/webdav.php
+++ b/apps/files_encryption/tests/webdav.php
@@ -216,7 +216,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
*
* @param bool $body
*
- * @note this init procedure is copied from /apps/files/remote.php
+ * @note this init procedure is copied from /apps/files/appinfo/remote.php
*/
function handleWebdavRequest($body = false) {
// Backends
diff --git a/lib/public/share.php b/lib/public/share.php
index 03d662676c6..6c93139b107 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -123,27 +123,32 @@ class Share {
return $path;
}
-
+
/**
* @brief Find which users can access a shared item
* @param $path to the file
* @param $user owner of the file
* @param include owner to the list of users with access to the file
* @return array
- * @note $path needs to be relative to user data dir, e.g. 'file.txt'
+ * @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
*/
- public static function getUsersSharingFile($path, $user, $includeOwner = false, $removeDuplicates = true) {
+ public static function getUsersSharingFile($path, $user, $includeOwner = false) {
- $path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
- $path = '';
$shares = array();
$publicShare = false;
+ $source = -1;
+ $cache = false;
+
$view = new \OC\Files\View('/' . $user . '/files/');
- foreach ($path_parts as $p) {
- $path .= '/' . $p;
- $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path));
+ $meta = $view->getFileInfo(\OC\Files\Filesystem::normalizePath($path));
+
+ if($meta !== false) {
$source = $meta['fileid'];
+ $cache = new \OC\Files\Cache\Cache($meta['storage']);
+ }
+
+ while ($source !== -1) {
// Fetch all shares of this file path from DB
$query = \OC_DB::prepare(
@@ -156,14 +161,13 @@ class Share {
$result = $query->execute(array($source, self::SHARE_TYPE_USER));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
- }
-
- while ($row = $result->fetchRow()) {
- $shares[] = $row['share_with'];
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ while ($row = $result->fetchRow()) {
+ $shares[] = $row['share_with'];
+ }
}
-
// We also need to take group shares into account
$query = \OC_DB::prepare(
@@ -176,32 +180,42 @@ class Share {
$result = $query->execute(array($source, self::SHARE_TYPE_GROUP));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
- }
-
- while ($row = $result->fetchRow()) {
- $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
- $shares = array_merge($shares, $usersInGroup);
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ while ($row = $result->fetchRow()) {
+ $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
+ $shares = array_merge($shares, $usersInGroup);
+ }
}
//check for public link shares
- $query = \OC_DB::prepare(
- 'SELECT share_with
- FROM
- `*PREFIX*share`
- WHERE
- item_source = ? AND share_type = ?'
- );
+ if (!$publicShare) {
+ $query = \OC_DB::prepare(
+ 'SELECT share_with
+ FROM
+ `*PREFIX*share`
+ WHERE
+ item_source = ? AND share_type = ?'
+ );
- $result = $query->execute(array($source, self::SHARE_TYPE_LINK));
+ $result = $query->execute(array($source, self::SHARE_TYPE_LINK));
- if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ if (\OCP\DB::isError($result)) {
+ \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
+ } else {
+ if ($result->fetchRow()) {
+ $publicShare = true;
+ }
+ }
}
-
- if ($result->fetchRow()) {
- $publicShare = true;
+
+ // let's get the parent for the next round
+ $meta = $cache->get((int)$source);
+ if($meta !== false) {
+ $source = (int)$meta['parent'];
+ } else {
+ $source = -1;
}
}
// Include owner in list of users, if requested