From 2d4af5dfca4acccb7e47c1cfe679086b570f089a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 25 Apr 2013 14:20:32 +0300 Subject: Correct function description $password is not supported --- lib/files/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index c0e9d215fb5..6cba4a4b8a4 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -287,7 +287,7 @@ class Filesystem { } /** - * fill in the correct values for $user, and $password placeholders + * fill in the correct values for $user * * @param string $input * @param string $input -- cgit v1.2.3 From 632221bed0a33d2b8d6c1eb7cc285f715967fd26 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 25 Apr 2013 14:27:08 +0300 Subject: Correct the parameter description Thanks @kabum --- lib/files/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 6cba4a4b8a4..8c8e80c1be4 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -289,7 +289,7 @@ class Filesystem { /** * fill in the correct values for $user * - * @param string $input + * @param string $user * @param string $input * @return string */ -- cgit v1.2.3 From cea56df59ec4530d78e66fd341738d77e0ab1745 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 25 Apr 2013 16:56:48 +0200 Subject: Have the filecache updater testcase clean the filesystem properly --- lib/files/filesystem.php | 1 + tests/lib/files/cache/updater.php | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index c0e9d215fb5..edd37d7b468 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -311,6 +311,7 @@ class Filesystem { */ static public function tearDown() { self::clearMounts(); + self::$defaultInstance = null; } /** diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index aaf932c97fe..dad3cd7e650 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -42,14 +42,11 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->scanner->scan(''); $this->cache = $this->storage->getCache(); + \OC\Files\Filesystem::tearDown(); if (!self::$user) { - if (!\OC\Files\Filesystem::getView()) { - self::$user = uniqid(); - \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); - } else { - self::$user = \OC_User::getUser(); - } + self::$user = uniqid(); } + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); -- cgit v1.2.3 From 809b5f81f6ee448563462ae8f642fbb8a6a11499 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Apr 2013 00:01:36 +0200 Subject: Further seperation of mount management logic --- apps/files_sharing/lib/cache.php | 2 +- apps/files_sharing/lib/sharedstorage.php | 2 +- lib/files/filesystem.php | 39 +++++- lib/files/mount.php | 223 ------------------------------- lib/files/mount/manager.php | 120 +++++++++++++++++ lib/files/mount/mount.php | 130 ++++++++++++++++++ lib/files/view.php | 2 +- lib/public/share.php | 2 +- lib/util.php | 1 + tests/lib/files/mount.php | 58 -------- tests/lib/files/mount/manager.php | 67 ++++++++++ tests/lib/streamwrappers.php | 4 +- 12 files changed, 357 insertions(+), 293 deletions(-) delete mode 100644 lib/files/mount.php create mode 100644 lib/files/mount/manager.php create mode 100644 lib/files/mount/mount.php delete mode 100644 tests/lib/files/mount.php create mode 100644 tests/lib/files/mount/manager.php (limited to 'lib/files/filesystem.php') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 9fccd0b46f3..733b7838760 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -44,7 +44,7 @@ class Shared_Cache extends Cache { $source = \OC_Share_Backend_File::getSource($target); if (isset($source['path']) && isset($source['fileOwner'])) { \OC\Files\Filesystem::initMountPoints($source['fileOwner']); - $mount = \OC\Files\Mount::findByNumericId($source['storage']); + $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); if ($mount) { $fullPath = $mount->getMountPoint().$source['path']; list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath); diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index ffd4e5ced22..2facad0f7e2 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -71,7 +71,7 @@ class Shared extends \OC\Files\Storage\Common { if ($source) { if (!isset($source['fullPath'])) { \OC\Files\Filesystem::initMountPoints($source['fileOwner']); - $mount = \OC\Files\Mount::findByNumericId($source['storage']); + $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); if ($mount) { $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path']; } else { diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 09732e67ac6..ad21a98fabc 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -34,6 +34,11 @@ const FREE_SPACE_UNKNOWN = -2; const FREE_SPACE_UNLIMITED = -3; class Filesystem { + /** + * @var Mount\Manager $mounts + */ + private static $mounts; + public static $loaded = false; /** * @var \OC\Files\View $defaultInstance @@ -147,7 +152,7 @@ class Filesystem { * @return string */ static public function getMountPoint($path) { - $mount = Mount::find($path); + $mount = self::$mounts->find($path); if ($mount) { return $mount->getMountPoint(); } else { @@ -163,7 +168,7 @@ class Filesystem { */ static public function getMountPoints($path) { $result = array(); - $mounts = Mount::findIn($path); + $mounts = self::$mounts->findIn($path); foreach ($mounts as $mount) { $result[] = $mount->getMountPoint(); } @@ -177,10 +182,26 @@ class Filesystem { * @return \OC\Files\Storage\Storage */ public static function getStorage($mountPoint) { - $mount = Mount::find($mountPoint); + $mount = self::$mounts->find($mountPoint); return $mount->getStorage(); } + /** + * @param $id + * @return Mount\Mount[] + */ + public static function getMountByStorageId($id) { + return self::$mounts->findByStorageId($id); + } + + /** + * @param $id + * @return Mount\Mount[] + */ + public static function getMountByNumericId($id) { + return self::$mounts->findByStorageId($id); + } + /** * resolve a path to a storage and internal path * @@ -188,7 +209,7 @@ class Filesystem { * @return array consisting of the storage and the internal path */ static public function resolvePath($path) { - $mount = Mount::find($path); + $mount = self::$mounts->find($path); if ($mount) { return array($mount->getStorage(), $mount->getInternalPath($path)); } else { @@ -201,6 +222,7 @@ class Filesystem { return false; } self::$defaultInstance = new View($root); + self::$mounts = new Mount\Manager(); //load custom mount config self::initMountPoints($user); @@ -210,6 +232,10 @@ class Filesystem { return true; } + static public function initMounts(){ + self::$mounts = new Mount\Manager(); + } + /** * Initialize system and personal mount points for a user * @@ -328,7 +354,7 @@ class Filesystem { * clear all mounts and storage backends */ public static function clearMounts() { - Mount::clear(); + self::$mounts->clear(); } /** @@ -339,7 +365,8 @@ class Filesystem { * @param string $mountpoint */ static public function mount($class, $arguments, $mountpoint) { - new Mount($class, $mountpoint, $arguments); + $mount = new Mount\Mount($class, $mountpoint, $arguments); + self::$mounts->addMount($mount); } /** diff --git a/lib/files/mount.php b/lib/files/mount.php deleted file mode 100644 index 0030d0ee7a6..00000000000 --- a/lib/files/mount.php +++ /dev/null @@ -1,223 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OC\Files; - -class Mount { - /** - * @var Mount[] - */ - static private $mounts = array(); - - /** - * @var \OC\Files\Storage\Storage $storage - */ - private $storage = null; - private $class; - private $storageId; - private $arguments = array(); - private $mountPoint; - - /** - * @param string|\OC\Files\Storage\Storage $storage - * @param string $mountpoint - * @param array $arguments (optional) - */ - public function __construct($storage, $mountpoint, $arguments = null) { - if (is_null($arguments)) { - $arguments = array(); - } - - $mountpoint = self::formatPath($mountpoint); - if ($storage instanceof \OC\Files\Storage\Storage) { - $this->class = get_class($storage); - $this->storage = $storage; - } else { - // Update old classes to new namespace - if (strpos($storage, 'OC_Filestorage_') !== false) { - $storage = '\OC\Files\Storage\\' . substr($storage, 15); - } - $this->class = $storage; - $this->arguments = $arguments; - } - $this->mountPoint = $mountpoint; - - self::$mounts[$this->mountPoint] = $this; - } - - /** - * @return string - */ - public function getMountPoint() { - return $this->mountPoint; - } - - /** - * @return \OC\Files\Storage\Storage - */ - private function createStorage() { - if (class_exists($this->class)) { - try { - return new $this->class($this->arguments); - } catch (\Exception $exception) { - \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR); - return null; - } - } else { - \OC_Log::write('core', 'storage backend ' . $this->class . ' not found', \OC_Log::ERROR); - return null; - } - } - - /** - * @return \OC\Files\Storage\Storage - */ - public function getStorage() { - if (is_null($this->storage)) { - $this->storage = $this->createStorage(); - } - return $this->storage; - } - - /** - * @return string - */ - public function getStorageId() { - if (!$this->storageId) { - if (is_null($this->storage)) { - $storage = $this->createStorage(); //FIXME: start using exceptions - if (is_null($storage)) { - return null; - } - $this->storage = $storage; - } - $this->storageId = $this->storage->getId(); - if (strlen($this->storageId) > 64) { - $this->storageId = md5($this->storageId); - } - } - return $this->storageId; - } - - /** - * @param string $path - * @return string - */ - public function getInternalPath($path) { - if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { - $internalPath = ''; - } else { - $internalPath = substr($path, strlen($this->mountPoint)); - } - return $internalPath; - } - - /** - * @param string $path - * @return string - */ - private static function formatPath($path) { - $path = Filesystem::normalizePath($path); - if (strlen($path) > 1) { - $path .= '/'; - } - return $path; - } - - /** - * Find the mount for $path - * - * @param $path - * @return Mount - */ - public static function find($path) { - \OC_Util::setupFS(); - $path = self::formatPath($path); - if (isset(self::$mounts[$path])) { - return self::$mounts[$path]; - } - - \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path)); - $foundMountPoint = ''; - $mountPoints = array_keys(self::$mounts); - foreach ($mountPoints as $mountpoint) { - if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) { - $foundMountPoint = $mountpoint; - } - } - if (isset(self::$mounts[$foundMountPoint])) { - return self::$mounts[$foundMountPoint]; - } else { - return null; - } - } - - /** - * Find all mounts in $path - * - * @param $path - * @return Mount[] - */ - public static function findIn($path) { - \OC_Util::setupFS(); - $path = self::formatPath($path); - $result = array(); - $pathLength = strlen($path); - $mountPoints = array_keys(self::$mounts); - foreach ($mountPoints as $mountPoint) { - if (substr($mountPoint, 0, $pathLength) === $path and strlen($mountPoint) > $pathLength) { - $result[] = self::$mounts[$mountPoint]; - } - } - return $result; - } - - public static function clear() { - self::$mounts = array(); - } - - /** - * Find mounts by storage id - * - * @param string $id - * @return Mount[] - */ - public static function findByStorageId($id) { - \OC_Util::setupFS(); - if (strlen($id) > 64) { - $id = md5($id); - } - $result = array(); - foreach (self::$mounts as $mount) { - if ($mount->getStorageId() === $id) { - $result[] = $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/mount/manager.php b/lib/files/mount/manager.php new file mode 100644 index 00000000000..25a5fe241cc --- /dev/null +++ b/lib/files/mount/manager.php @@ -0,0 +1,120 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Mount; + +use \OC\Files\Filesystem; + +class Manager { + /** + * @var Mount[] + */ + private $mounts = array(); + + /** + * @param Mount $mount + */ + public function addMount($mount) { + $this->mounts[$mount->getMountPoint()] = $mount; + } + + /** + * Find the mount for $path + * + * @param $path + * @return Mount + */ + public function find($path) { + \OC_Util::setupFS(); + $path = $this->formatPath($path); + if (isset($this->mounts[$path])) { + return $this->mounts[$path]; + } + + \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path)); + $foundMountPoint = ''; + $mountPoints = array_keys($this->mounts); + foreach ($mountPoints as $mountpoint) { + if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) { + $foundMountPoint = $mountpoint; + } + } + if (isset($this->mounts[$foundMountPoint])) { + return $this->mounts[$foundMountPoint]; + } else { + return null; + } + } + + /** + * Find all mounts in $path + * + * @param $path + * @return Mount[] + */ + public function findIn($path) { + \OC_Util::setupFS(); + $path = $this->formatPath($path); + $result = array(); + $pathLength = strlen($path); + $mountPoints = array_keys($this->mounts); + foreach ($mountPoints as $mountPoint) { + if (substr($mountPoint, 0, $pathLength) === $path and strlen($mountPoint) > $pathLength) { + $result[] = $this->mounts[$mountPoint]; + } + } + return $result; + } + + public function clear() { + $this->mounts = array(); + } + + /** + * Find mounts by storage id + * + * @param string $id + * @return Mount[] + */ + public function findByStorageId($id) { + \OC_Util::setupFS(); + if (strlen($id) > 64) { + $id = md5($id); + } + $result = array(); + foreach ($this->mounts as $mount) { + if ($mount->getStorageId() === $id) { + $result[] = $mount; + } + } + return $result; + } + + /** + * Find mounts by numeric storage id + * + * @param string $id + * @return Mount + */ + public function findByNumericId($id) { + $storageId = \OC\Files\Cache\Storage::getStorageId($id); + return $this->findByStorageId($storageId); + } + + /** + * @param string $path + * @return string + */ + private function formatPath($path) { + $path = Filesystem::normalizePath($path); + if (strlen($path) > 1) { + $path .= '/'; + } + return $path; + } +} diff --git a/lib/files/mount/mount.php b/lib/files/mount/mount.php new file mode 100644 index 00000000000..69b8285ab4c --- /dev/null +++ b/lib/files/mount/mount.php @@ -0,0 +1,130 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Mount; + +use \OC\Files\Filesystem; + +class Mount { + + + /** + * @var \OC\Files\Storage\Storage $storage + */ + private $storage = null; + private $class; + private $storageId; + private $arguments = array(); + private $mountPoint; + + /** + * @param string|\OC\Files\Storage\Storage $storage + * @param string $mountpoint + * @param array $arguments (optional) + */ + public function __construct($storage, $mountpoint, $arguments = null) { + if (is_null($arguments)) { + $arguments = array(); + } + + $mountpoint = $this->formatPath($mountpoint); + if ($storage instanceof \OC\Files\Storage\Storage) { + $this->class = get_class($storage); + $this->storage = $storage; + } else { + // Update old classes to new namespace + if (strpos($storage, 'OC_Filestorage_') !== false) { + $storage = '\OC\Files\Storage\\' . substr($storage, 15); + } + $this->class = $storage; + $this->arguments = $arguments; + } + $this->mountPoint = $mountpoint; + } + + /** + * @return string + */ + public function getMountPoint() { + return $this->mountPoint; + } + + /** + * create the storage that is mounted + * + * @return \OC\Files\Storage\Storage + */ + private function createStorage() { + if (class_exists($this->class)) { + try { + return new $this->class($this->arguments); + } catch (\Exception $exception) { + \OC_Log::write('core', $exception->getMessage(), \OC_Log::ERROR); + return null; + } + } else { + \OC_Log::write('core', 'storage backend ' . $this->class . ' not found', \OC_Log::ERROR); + return null; + } + } + + /** + * @return \OC\Files\Storage\Storage + */ + public function getStorage() { + if (is_null($this->storage)) { + $this->storage = $this->createStorage(); + } + return $this->storage; + } + + /** + * @return string + */ + public function getStorageId() { + if (!$this->storageId) { + if (is_null($this->storage)) { + $storage = $this->createStorage(); //FIXME: start using exceptions + if (is_null($storage)) { + return null; + } + $this->storage = $storage; + } + $this->storageId = $this->storage->getId(); + if (strlen($this->storageId) > 64) { + $this->storageId = md5($this->storageId); + } + } + return $this->storageId; + } + + /** + * @param string $path + * @return string + */ + public function getInternalPath($path) { + if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { + $internalPath = ''; + } else { + $internalPath = substr($path, strlen($this->mountPoint)); + } + return $internalPath; + } + + /** + * @param string $path + * @return string + */ + private function formatPath($path) { + $path = Filesystem::normalizePath($path); + if (strlen($path) > 1) { + $path .= '/'; + } + return $path; + } +} diff --git a/lib/files/view.php b/lib/files/view.php index 0da104c107e..f89b7f66ffd 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -977,7 +977,7 @@ class View { */ public function getPath($id) { list($storage, $internalPath) = Cache\Cache::getById($id); - $mounts = Mount::findByStorageId($storage); + $mounts = Filesystem::getMountByStorageId($storage); foreach ($mounts as $mount) { /** * @var \OC\Files\Mount $mount diff --git a/lib/public/share.php b/lib/public/share.php index 4b337530be8..525fe7e8533 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -875,7 +875,7 @@ class Share { $row['path'] = '/Shared/'.basename($row['path']); } else { if (!isset($mounts[$row['storage']])) { - $mounts[$row['storage']] = \OC\Files\Mount::findByNumericId($row['storage']); + $mounts[$row['storage']] = \OC\Files\Filesystem::getMountByNumericId($row['storage']); } if ($mounts[$row['storage']]) { $path = $mounts[$row['storage']]->getMountPoint().$row['path']; diff --git a/lib/util.php b/lib/util.php index 810593358a5..f62c2a42d73 100755 --- a/lib/util.php +++ b/lib/util.php @@ -38,6 +38,7 @@ class OC_Util { $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); //first set up the local "root" storage + \OC\Files\Filesystem::initMounts(); if(!self::$rootMounted) { \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/'); self::$rootMounted=true; diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php deleted file mode 100644 index a3dc06cc668..00000000000 --- a/tests/lib/files/mount.php +++ /dev/null @@ -1,58 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\Files; - -use \OC\Files\Storage\Temporary; - -class LongId extends Temporary { - public function getId() { - return 'long:' . str_repeat('foo', 50) . parent::getId(); - } -} - -class Mount extends \PHPUnit_Framework_TestCase { - public function setup() { - \OC_Util::setupFS(); - \OC\Files\Mount::clear(); - } - - public function testFind() { - $this->assertNull(\OC\Files\Mount::find('/')); - - $rootMount = new \OC\Files\Mount(new Temporary(array()), '/'); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/')); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/foo/bar')); - - $storage = new Temporary(array()); - $mount = new \OC\Files\Mount($storage, '/foo'); - $this->assertEquals($rootMount, \OC\Files\Mount::find('/')); - $this->assertEquals($mount, \OC\Files\Mount::find('/foo/bar')); - - $this->assertEquals(1, count(\OC\Files\Mount::findIn('/'))); - new \OC\Files\Mount(new Temporary(array()), '/bar'); - $this->assertEquals(2, count(\OC\Files\Mount::findIn('/'))); - - $id = $mount->getStorageId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); - - $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); - $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id)); - } - - public function testLong() { - $storage = new LongId(array()); - $mount = new \OC\Files\Mount($storage, '/foo'); - - $id = $mount->getStorageId(); - $storageId = $storage->getId(); - $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))); - } -} diff --git a/tests/lib/files/mount/manager.php b/tests/lib/files/mount/manager.php new file mode 100644 index 00000000000..154c35ccead --- /dev/null +++ b/tests/lib/files/mount/manager.php @@ -0,0 +1,67 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Mount; + +use \OC\Files\Storage\Temporary; + +class LongId extends Temporary { + public function getId() { + return 'long:' . str_repeat('foo', 50) . parent::getId(); + } +} + +class Manager extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Files\Mount\Manager + */ + private $manager; + + public function setup() { + $this->manager = new \OC\Files\Mount\Manager(); + } + + public function testFind() { + $this->assertNull($this->manager->find('/')); + + $rootMount = new \OC\Files\Mount\Mount(new Temporary(array()), '/'); + $this->manager->addMount($rootMount); + $this->assertEquals($rootMount, $this->manager->find('/')); + $this->assertEquals($rootMount, $this->manager->find('/foo/bar')); + + $storage = new Temporary(array()); + $mount1 = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->manager->addMount($mount1); + $this->assertEquals($rootMount, $this->manager->find('/')); + $this->assertEquals($mount1, $this->manager->find('/foo/bar')); + + $this->assertEquals(1, count($this->manager->findIn('/'))); + $mount2 = new \OC\Files\Mount\Mount(new Temporary(array()), '/bar'); + $this->manager->addMount($mount2); + $this->assertEquals(2, count($this->manager->findIn('/'))); + + $id = $mount1->getStorageId(); + $this->assertEquals(array($mount1), $this->manager->findByStorageId($id)); + + $mount3 = new \OC\Files\Mount\Mount($storage, '/foo/bar'); + $this->manager->addMount($mount3); + $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id)); + } + + public function testLong() { + $storage = new LongId(array()); + $mount = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->manager->addMount($mount); + + $id = $mount->getStorageId(); + $storageId = $storage->getId(); + $this->assertEquals(array($mount), $this->manager->findByStorageId($id)); + $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId)); + $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId))); + } +} diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index 2237ee7d378..c7e51ccfa48 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -77,10 +77,10 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { } public function testOC() { - \OC\Files\Mount::clear(); + \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); $storage->file_put_contents('foo.txt', 'asd'); - new \OC\Files\Mount($storage, '/'); + \OC\Files\Filesystem::mount($storage, array(), '/'); $this->assertTrue(file_exists('oc:///foo.txt')); $this->assertEquals('asd', file_get_contents('oc:///foo.txt')); -- cgit v1.2.3 From 7039421efc80f3551026d3f16ba6887e7be02234 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 2 May 2013 17:47:11 -0400 Subject: Fix retrieving of mount points for shared storage, fix #3218 --- apps/files_sharing/lib/cache.php | 27 ++++++++++++++++++++++++--- apps/files_sharing/lib/sharedstorage.php | 4 ++-- lib/files/filesystem.php | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 1cb457cb987..2160fe9a393 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -45,8 +45,8 @@ class Shared_Cache extends Cache { if (isset($source['path']) && isset($source['fileOwner'])) { \OC\Files\Filesystem::initMountPoints($source['fileOwner']); $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); - if ($mount) { - $fullPath = $mount->getMountPoint().$source['path']; + if (is_array($mount)) { + $fullPath = $mount[key($mount)]->getMountPoint().$source['path']; list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath); if ($storage) { $this->files[$target] = $internalPath; @@ -60,6 +60,14 @@ class Shared_Cache extends Cache { return false; } + public function getNumericStorageId() { + if (isset($this->numericId)) { + return $this->numericId; + } else { + return false; + } + } + /** * get the stored metadata of a file or folder * @@ -267,4 +275,17 @@ class Shared_Cache extends Cache { return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL); } -} + /** + * find a folder in the cache which has not been fully scanned + * + * If multiply incomplete folders are in the cache, the one with the highest id will be returned, + * use the one with the highest id gives the best result with the background scanner, since that is most + * likely the folder where we stopped scanning previously + * + * @return string|bool the path of the folder or false when no folder matched + */ + public function getIncomplete() { + return false; + } + +} \ No newline at end of file diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 2facad0f7e2..5c23a9eb0d0 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -72,8 +72,8 @@ class Shared extends \OC\Files\Storage\Common { if (!isset($source['fullPath'])) { \OC\Files\Filesystem::initMountPoints($source['fileOwner']); $mount = \OC\Files\Filesystem::getMountByNumericId($source['storage']); - if ($mount) { - $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path']; + if (is_array($mount)) { + $this->files[$target]['fullPath'] = $mount[key($mount)]->getMountPoint().$source['path']; } else { $this->files[$target]['fullPath'] = false; } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index ad21a98fabc..eadd8a93faf 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -199,7 +199,7 @@ class Filesystem { * @return Mount\Mount[] */ public static function getMountByNumericId($id) { - return self::$mounts->findByStorageId($id); + return self::$mounts->findByNumericId($id); } /** -- cgit v1.2.3 From 807740a07a5385b0761aa23128f859a203e8b71a Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 15 May 2013 10:19:38 +0200 Subject: fix for losing mount point "/" --- lib/files/filesystem.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index eadd8a93faf..d60d430d77c 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -222,7 +222,10 @@ class Filesystem { return false; } self::$defaultInstance = new View($root); - self::$mounts = new Mount\Manager(); + + if(!self::$mounts) { + self::$mounts = new Mount\Manager(); + } //load custom mount config self::initMountPoints($user); -- cgit v1.2.3 From c50bf3e3c54ccbad6b58538fb131924d4f0ff3d7 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 15 May 2013 10:19:38 +0200 Subject: fix for losing mount point "/" --- lib/files/filesystem.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index eadd8a93faf..d60d430d77c 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -222,7 +222,10 @@ class Filesystem { return false; } self::$defaultInstance = new View($root); - self::$mounts = new Mount\Manager(); + + if(!self::$mounts) { + self::$mounts = new Mount\Manager(); + } //load custom mount config self::initMountPoints($user); -- cgit v1.2.3 From 41e2d64c86fffc3e507a1ad0788bcb498db2c640 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 19 May 2013 14:15:49 -0400 Subject: Add support for copying/moving folders between storages, move isIgnoredDir() to Filesystem --- lib/files/cache/scanner.php | 14 +------------- lib/files/filesystem.php | 13 +++++++++++++ lib/files/view.php | 32 ++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 21 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index 661bc486330..0b1947f17ca 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -115,7 +115,7 @@ class Scanner { \OC_DB::beginTransaction(); while ($file = readdir($dh)) { $child = ($path) ? $path . '/' . $file : $file; - if (!$this->isIgnoredDir($file)) { + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { $data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW); if ($data) { if ($data['size'] === -1) { @@ -149,18 +149,6 @@ class Scanner { return $size; } - /** - * @brief check if the directory should be ignored when scanning - * NOTE: the special directories . and .. would cause never ending recursion - * @param String $dir - * @return boolean - */ - private function isIgnoredDir($dir) { - if ($dir === '.' || $dir === '..') { - return true; - } - return false; - } /** * @brief check if the file should be ignored when scanning * NOTE: files with a '.part' extension are ignored as well! diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index d60d430d77c..99d87011df2 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -453,6 +453,19 @@ class Filesystem { return (in_array($filename, $blacklist)); } + /** + * @brief check if the directory should be ignored when scanning + * NOTE: the special directories . and .. would cause never ending recursion + * @param String $dir + * @return boolean + */ + static public function isIgnoredDir($dir) { + if ($dir === '.' || $dir === '..') { + return true; + } + return false; + } + /** * following functions are equivalent to their php builtin equivalents for arguments/return values. */ diff --git a/lib/files/view.php b/lib/files/view.php index f35e1e3dc16..875a6c1a1f8 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -372,11 +372,18 @@ class View { $result = false; } } else { - $source = $this->fopen($path1 . $postFix1, 'r'); - $target = $this->fopen($path2 . $postFix2, 'w'); - list($count, $result) = \OC_Helper::streamCopy($source, $target); - list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); - $storage1->unlink($internalPath1); + if ($this->is_dir($path1)) { + $result = $this->copy($path1, $path2); + if ($result === true) { + $result = $this->deleteAll($path1); + } + } else { + $source = $this->fopen($path1 . $postFix1, 'r'); + $target = $this->fopen($path2 . $postFix2, 'w'); + list($count, $result) = \OC_Helper::streamCopy($source, $target); + list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); + $storage1->unlink($internalPath1); + } } if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1)) { \OC_Hook::emit( @@ -459,9 +466,18 @@ class View { $result = false; } } else { - $source = $this->fopen($path1 . $postFix1, 'r'); - $target = $this->fopen($path2 . $postFix2, 'w'); - list($count, $result) = \OC_Helper::streamCopy($source, $target); + if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) { + $this->mkdir($path2); + while ($file = readdir($dh)) { + if (!Filesystem::isIgnoredDir($file)) { + $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file); + } + } + } else { + $source = $this->fopen($path1 . $postFix1, 'r'); + $target = $this->fopen($path2 . $postFix2, 'w'); + list($count, $result) = \OC_Helper::streamCopy($source, $target); + } } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( -- cgit v1.2.3 From 079f918d5ca0d242e77717aaeac82bcf011dc745 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Sun, 19 May 2013 22:30:03 +0200 Subject: fix for webdav and wrong reference for findByStorageId --- lib/files/cache/backgroundwatcher.php | 2 +- lib/files/filesystem.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php index 7549745e7d7..b5770d0582b 100644 --- a/lib/files/cache/backgroundwatcher.php +++ b/lib/files/cache/backgroundwatcher.php @@ -30,7 +30,7 @@ class BackgroundWatcher { return; } list($storageId, $internalPath) = $cacheItem; - $mounts = Mount::findByStorageId($storageId); + $mounts = Mount\Manager::findByStorageId($storageId); if (count($mounts) === 0) { //if the storage we need isn't mounted on default, try to find a user that has access to the storage diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index d60d430d77c..d0cac9dc1d3 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -236,7 +236,9 @@ class Filesystem { } static public function initMounts(){ - self::$mounts = new Mount\Manager(); + if(!self::$mounts) { + self::$mounts = new Mount\Manager(); + } } /** -- cgit v1.2.3 From b3b6738d599480fc9bf40a53313598c4766571fb Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Mon, 20 May 2013 01:47:35 +0200 Subject: Revert "fix for webdav and wrong reference for findByStorageId" This reverts commit 079f918d5ca0d242e77717aaeac82bcf011dc745. --- lib/files/cache/backgroundwatcher.php | 2 +- lib/files/filesystem.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php index b5770d0582b..7549745e7d7 100644 --- a/lib/files/cache/backgroundwatcher.php +++ b/lib/files/cache/backgroundwatcher.php @@ -30,7 +30,7 @@ class BackgroundWatcher { return; } list($storageId, $internalPath) = $cacheItem; - $mounts = Mount\Manager::findByStorageId($storageId); + $mounts = Mount::findByStorageId($storageId); if (count($mounts) === 0) { //if the storage we need isn't mounted on default, try to find a user that has access to the storage diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index d0cac9dc1d3..d60d430d77c 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -236,9 +236,7 @@ class Filesystem { } static public function initMounts(){ - if(!self::$mounts) { - self::$mounts = new Mount\Manager(); - } + self::$mounts = new Mount\Manager(); } /** -- cgit v1.2.3 From 58a8d67a9b3c48567bcc40cc02444311c6773275 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Mon, 20 May 2013 01:57:16 +0200 Subject: fix for webdav because initMounts() is triggered twice so we lost the root path --- lib/files/filesystem.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index d60d430d77c..d0cac9dc1d3 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -236,7 +236,9 @@ class Filesystem { } static public function initMounts(){ - self::$mounts = new Mount\Manager(); + if(!self::$mounts) { + self::$mounts = new Mount\Manager(); + } } /** -- cgit v1.2.3 From 736f10039dd1b494966f1214916dc62119478176 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Fri, 24 May 2013 20:36:20 +0200 Subject: changed builtin normalizer to \OC_Util::normalizeUnicode --- lib/files/cache/cache.php | 7 +------ lib/files/filesystem.php | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'lib/files/filesystem.php') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index a7e634c8e41..865abd5286f 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -566,11 +566,6 @@ class Cache { */ public function normalize($path) { - //normalize unicode if possible - if (class_exists('Normalizer')) { - $path = \Normalizer::normalize($path); - } - - return $path; + return \OC_Util::normalizeUnicode($path); } } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index d60d430d77c..5d7565f0d83 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -616,9 +616,8 @@ class Filesystem { $path = substr($path, 0, -1); } //normalize unicode if possible - if (class_exists('Normalizer')) { - $path = \Normalizer::normalize($path); - } + $path = \OC_Util::normalizeUnicode($path); + return $path; } -- cgit v1.2.3