From 8174e5faf18fcd762efce5ffdfabfa1102580dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 9 Feb 2013 19:03:03 +0100 Subject: [PATCH 1/2] make MappedLocal available and testable within Linux as well --- lib/files/storage/local.php | 4 ++- lib/files/storage/mappedlocal.php | 2 +- tests/lib/files/storage/mappedlocal.php | 40 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/lib/files/storage/mappedlocal.php diff --git a/lib/files/storage/local.php b/lib/files/storage/local.php index d387a89832..038d68bf46 100644 --- a/lib/files/storage/local.php +++ b/lib/files/storage/local.php @@ -9,7 +9,9 @@ namespace OC\Files\Storage; if (\OC_Util::runningOnWindows()) { - require_once 'mappedlocal.php'; + class Local extends MappedLocal { + + } } else { /** diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php index 80dd79bc41..411b053737 100644 --- a/lib/files/storage/mappedlocal.php +++ b/lib/files/storage/mappedlocal.php @@ -10,7 +10,7 @@ namespace OC\Files\Storage; /** * for local filestore, we only have to map the paths */ -class Local extends \OC\Files\Storage\Common{ +class MappedLocal extends \OC\Files\Storage\Common{ protected $datadir; private $mapper; diff --git a/tests/lib/files/storage/mappedlocal.php b/tests/lib/files/storage/mappedlocal.php new file mode 100644 index 0000000000..b483f3a195 --- /dev/null +++ b/tests/lib/files/storage/mappedlocal.php @@ -0,0 +1,40 @@ +. +* +*/ + +namespace Test\Files\Storage; + +class MappedLocal extends Storage { + /** + * @var string tmpDir + */ + private $tmpDir; + public function setUp() { + $this->tmpDir=\OC_Helper::tmpFolder(); + $this->instance=new \OC\Files\Storage\MappedLocal(array('datadir'=>$this->tmpDir)); + } + + public function tearDown() { + \OC_Helper::rmdirr($this->tmpDir); + unset($this->instance); + } +} + From 92e6409f4008d21c8507310d7b6ce0f64fc29b71 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 11 Feb 2013 13:53:10 +0100 Subject: [PATCH 2/2] fixing mappedlocal storage to work on non-windows as well this allows us to run unit tests on linux - necessary to enable easy regression testing --- lib/files/mapper.php | 16 +++++++++++++++- lib/files/storage/mappedlocal.php | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/files/mapper.php b/lib/files/mapper.php index 71b665e49b..2d29a8532b 100644 --- a/lib/files/mapper.php +++ b/lib/files/mapper.php @@ -117,6 +117,9 @@ class Mapper $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?'); $result = $query->execute(array(md5($logicPath))); $result = $result->fetchRow(); + if ($result === false) { + return null; + } return $result['physic_path']; } @@ -160,11 +163,16 @@ class Mapper $sluggedElements = array(); // skip slugging the drive letter on windows - TODO: test if local path - if (strpos(strtolower(php_uname('s')), 'win') !== false) { + if (\OC_Util::runningOnWindows()) { $sluggedElements[]= $pathElements[0]; array_shift($pathElements); } foreach ($pathElements as $pathElement) { + // remove empty elements + if (empty($pathElement)) { + continue; + } + // TODO: remove file ext before slugify on last element $sluggedElements[] = self::slugify($pathElement); } @@ -177,6 +185,12 @@ class Mapper array_pop($sluggedElements); array_push($sluggedElements, $last.'-'.$index); } + + // on non-windows systems add the leading / if necessary + if (!\OC_Util::runningOnWindows() and $path[0] === '/') { + return DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $sluggedElements); + } + return implode(DIRECTORY_SEPARATOR, $sluggedElements); } diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php index 411b053737..218465d8ee 100644 --- a/lib/files/storage/mappedlocal.php +++ b/lib/files/storage/mappedlocal.php @@ -329,6 +329,9 @@ class MappedLocal extends \OC\Files\Storage\Common{ if(strpos($path, '/') === 0) { $path = substr($path, 1); } + if ($path === false) { + return ''; + } return $path; }