Fix fetching source path of shared files

This commit is contained in:
Michael Gapczynski 2013-03-07 11:12:59 -05:00
parent e5a497c924
commit a5cab28bea
6 changed files with 62 additions and 19 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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 = '*';

View File

@ -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)));
}
}