diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 0aeb763d89..fa43e87b49 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -73,7 +73,9 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { if ($format == self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call return array( + 'parent' => $items[key($items)]['parent'], 'path' => $items[key($items)]['path'], + 'storage' => $items[key($items)]['storage'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner'] ); @@ -139,13 +141,28 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); if ($source) { $source['path'] = $source['path'].substr($target, strlen($folder)); - return $source; } } else { $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); - if ($source) { - return $source; + } + if ($source) { + if (isset($source['parent'])) { + $parent = $source['parent']; + while (isset($parent)) { + $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); + $item = $query->execute(array($parent))->fetchRow(); + if (isset($item['parent'])) { + $parent = $item['parent']; + } else { + $fileOwner = $item['uid_owner']; + break; + } + } + } else { + $fileOwner = $source['uid_owner']; } + $source['fileOwner'] = $fileOwner; + return $source; } \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR); return false; diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 5a9864b64b..be0e59e673 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -45,11 +45,7 @@ class Shared extends \OC\Files\Storage\Common { */ private function getFile($target) { if (!isset($this->files[$target])) { - $source = \OC_Share_Backend_File::getSource($target); - if ($source) { - $source['path'] = '/'.$source['uid_owner'].'/'.$source['path']; - } - $this->files[$target] = $source; + $this->files[$target] = \OC_Share_Backend_File::getSource($target); } return $this->files[$target]; } @@ -62,8 +58,16 @@ class Shared extends \OC\Files\Storage\Common { private function getSourcePath($target) { $source = $this->getFile($target); if ($source) { - \OC\Files\Filesystem::initMountPoints($source['uid_owner']); - return $source['path']; + if (!isset($source['fullPath'])) { + \OC\Files\Filesystem::initMountPoints($source['fileOwner']); + $mount = \OC\Files\Mount::findByNumericId($source['storage']); + if ($mount) { + $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path']; + } else { + $this->files[$target]['fullPath'] = false; + } + } + return $this->files[$target]['fullPath']; } return false; } @@ -430,7 +434,7 @@ class Shared extends \OC\Files\Storage\Common { } $source = $this->getFile($path); if ($source) { - return $source['uid_owner']; + return $source['fileOwner']; } return false; } diff --git a/lib/files/mount.php b/lib/files/mount.php index 6e99d8eabb..1c9382d78e 100644 --- a/lib/files/mount.php +++ b/lib/files/mount.php @@ -176,10 +176,12 @@ class Mount { } /** + * Find mounts by storage id + * * @param string $id - * @return \OC\Files\Storage\Storage[] + * @return Mount[] */ - public static function findById($id) { + public static function findByStorageId($id) { if (strlen($id) > 64) { $id = md5($id); } @@ -191,4 +193,24 @@ class Mount { } return $result; } + + /** + * Find mounts by numeric storage id + * + * @param string $id + * @return Mount + */ + public static function findByNumericId($id) { + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); + $result = $query->execute(array($id))->fetchOne(); + if ($result) { + $id = $result; + foreach (self::$mounts as $mount) { + if ($mount->getStorageId() === $id) { + return $mount; + } + } + } + return false; + } } diff --git a/lib/files/view.php b/lib/files/view.php index 3e2cb080e1..4ed3234552 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -960,7 +960,7 @@ class View { */ public function getPath($id) { list($storage, $internalPath) = Cache\Cache::getById($id); - $mounts = Mount::findById($storage); + $mounts = Mount::findByStorageId($storage); foreach ($mounts as $mount) { /** * @var \OC\Files\Mount $mount diff --git a/lib/public/share.php b/lib/public/share.php index 8146a23f36..59f41a9bfd 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -786,7 +786,7 @@ class Share { } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; } } else { $select = '*'; diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php index 4e6aaf0679..6a5c025b0e 100644 --- a/tests/lib/files/mount.php +++ b/tests/lib/files/mount.php @@ -42,7 +42,7 @@ class Mount extends \PHPUnit_Framework_TestCase { $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); - $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id)); + $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id)); } public function testLong() { @@ -51,8 +51,8 @@ class Mount extends \PHPUnit_Framework_TestCase { $id = $mount->getStorageId(); $storageId = $storage->getId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId))); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId))); } }