]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix fetching source path of shared files
authorMichael Gapczynski <mtgap@owncloud.com>
Thu, 7 Mar 2013 16:12:59 +0000 (11:12 -0500)
committerMichael Gapczynski <mtgap@owncloud.com>
Thu, 7 Mar 2013 16:12:59 +0000 (11:12 -0500)
apps/files_sharing/lib/share/file.php
apps/files_sharing/lib/sharedstorage.php
lib/files/mount.php
lib/files/view.php
lib/public/share.php
tests/lib/files/mount.php

index 0aeb763d89ad21d0c99d44f22f1940ef32501158..fa43e87b49e39be3091e81c27501bbe36704b1e7 100644 (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;
index 5a9864b64bae035873c12cef62d7f8758069883a..be0e59e6732dc52bbc8e0ec99fdf94200b41dde6 100644 (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;
        }
index 6e99d8eabb49f000305b0a77386963c991bcb9c4..1c9382d78e7d5347b04893217a24c1a4fc4f173b 100644 (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;
+       }
 }
index 3e2cb080e1dbd745bd5e666078ba5fca7841981c..4ed3234552ed5fc3dfc7a4465a43da731849a755 100644 (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
index 8146a23f360fc3c9f8bcf13c4e05008734c1a4d5..59f41a9bfd6f59a0dbfacd9444b263a42c7d9ad0 100644 (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 = '*';
index 4e6aaf0679b5b130f6344bc48aca219b533c7c1a..6a5c025b0e17035ea7a7b2e1c0a8fa57fa5d9cd5 100644 (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)));
        }
 }