From e3ba0c3082841afe84b677fdc1fc07692c5a6cd3 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 14:46:09 +0100 Subject: [PATCH 1/5] adding a new test class for mapped local using a dot in the datadir - reflects the issue described in #1659 --- .../storage/mappedlocalwithdotteddatadir.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/lib/files/storage/mappedlocalwithdotteddatadir.php diff --git a/tests/lib/files/storage/mappedlocalwithdotteddatadir.php b/tests/lib/files/storage/mappedlocalwithdotteddatadir.php new file mode 100644 index 0000000000..abd0b3d85c --- /dev/null +++ b/tests/lib/files/storage/mappedlocalwithdotteddatadir.php @@ -0,0 +1,40 @@ +. +* +*/ + +namespace Test\Files\Storage; + +class MappedLocalWithDottedDataDir extends Storage { + /** + * @var string tmpDir + */ + private $tmpDir; + public function setUp() { + $this->tmpDir = \OC_Helper::tmpFolder().'dir.123'.DIRECTORY_SEPARATOR; + $this->instance=new \OC\Files\Storage\MappedLocal(array('datadir'=>$this->tmpDir)); + } + + public function tearDown() { + \OC_Helper::rmdirr($this->tmpDir); + unset($this->instance); + } +} + From c0f3d8578a48ceee1a45fda4077696643747fc45 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:40:07 +0100 Subject: [PATCH 2/5] folder should be created :-( --- tests/lib/files/storage/mappedlocalwithdotteddatadir.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/files/storage/mappedlocalwithdotteddatadir.php b/tests/lib/files/storage/mappedlocalwithdotteddatadir.php index abd0b3d85c..d2e5e2e97a 100644 --- a/tests/lib/files/storage/mappedlocalwithdotteddatadir.php +++ b/tests/lib/files/storage/mappedlocalwithdotteddatadir.php @@ -27,8 +27,10 @@ class MappedLocalWithDottedDataDir extends Storage { * @var string tmpDir */ private $tmpDir; + public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder().'dir.123'.DIRECTORY_SEPARATOR; + mkdir($this->tmpDir); $this->instance=new \OC\Files\Storage\MappedLocal(array('datadir'=>$this->tmpDir)); } From 191da024fa312c6322c00073c6cf48dc8e282ed0 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:40:52 +0100 Subject: [PATCH 3/5] new test cases added to search in sub folders --- tests/lib/files/storage/storage.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index c74a16f509..f78f66d8b8 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -223,6 +223,22 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertContains('/logo-wide.png', $result); } + public function testSearchInSubFolder() { + $this->instance->mkdir('sub') + ; + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $this->instance->file_put_contents('/sub/lorem.txt', file_get_contents($textFile, 'r')); + $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png'; + $this->instance->file_put_contents('/sub/logo-wide.png', file_get_contents($pngFile, 'r')); + $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg'; + $this->instance->file_put_contents('/sub/logo-wide.svg', file_get_contents($svgFile, 'r')); + + $result = $this->instance->search('logo'); + $this->assertEquals(2, count($result)); + $this->assertContains('/sub/logo-wide.svg', $result); + $this->assertContains('/sub/logo-wide.png', $result); + } + public function testFOpen() { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; From b488800bd5665eaa11b54002509e9e8b85c0780e Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:41:22 +0100 Subject: [PATCH 4/5] fix error in recursive search --- lib/files/storage/mappedlocal.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php index e707f71d71..434c10bcbf 100644 --- a/lib/files/storage/mappedlocal.php +++ b/lib/files/storage/mappedlocal.php @@ -20,7 +20,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ $this->datadir.='/'; } - $this->mapper= new \OC\Files\Mapper(); + $this->mapper= new \OC\Files\Mapper($this->datadir); } public function __destruct() { if (defined('PHPUNIT_RUN')) { @@ -274,7 +274,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ return $this->buildPath($path); } - protected function searchInDir($query, $dir='', $isLogicPath=true) { + protected function searchInDir($query, $dir='') { $files=array(); $physicalDir = $this->buildPath($dir); foreach (scandir($physicalDir) as $item) { @@ -287,7 +287,7 @@ class MappedLocal extends \OC\Files\Storage\Common{ $files[]=$dir.'/'.$item; } if(is_dir($physicalItem)) { - $files=array_merge($files, $this->searchInDir($query, $physicalItem, false)); + $files=array_merge($files, $this->searchInDir($query, $dir.'/'.$item)); } } return $files; From 40739350c9b674551f0b218220054ec4f303f154 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 15 Feb 2013 17:42:17 +0100 Subject: [PATCH 5/5] class Mapper no respects an unchanged physical root which will be excluded from slugifying the path --- lib/files/mapper.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/files/mapper.php b/lib/files/mapper.php index cd163dcbfc..520fadbd8c 100644 --- a/lib/files/mapper.php +++ b/lib/files/mapper.php @@ -7,6 +7,12 @@ namespace OC\Files; */ class Mapper { + private $unchangedPhysicalRoot; + + public function __construct($rootDir) { + $this->unchangedPhysicalRoot = $rootDir; + } + /** * @param string $logicPath * @param bool $create indicates if the generated physical name shall be stored in the database or not @@ -23,7 +29,7 @@ class Mapper /** * @param string $physicalPath - * @return string|null + * @return string */ public function physicalToLogic($physicalPath) { $logicPath = $this->resolvePhysicalPath($physicalPath); @@ -39,6 +45,7 @@ class Mapper * @param string $path * @param bool $isLogicPath indicates if $path is logical or physical * @param $recursive + * @return void */ public function removePath($path, $isLogicPath, $recursive) { if ($recursive) { @@ -159,14 +166,11 @@ class Mapper } private function slugifyPath($path, $index=null) { + $path = $this->stripRootFolder($path, $this->unchangedPhysicalRoot); + $pathElements = explode('/', $path); $sluggedElements = array(); - // skip slugging the drive letter on windows - TODO: test if local path - if (\OC_Util::runningOnWindows()) { - $sluggedElements[]= $pathElements[0]; - array_shift($pathElements); - } foreach ($pathElements as $pathElement) { // remove empty elements if (empty($pathElement)) { @@ -186,12 +190,8 @@ class Mapper 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); + $sluggedPath = $this->unchangedPhysicalRoot.implode(DIRECTORY_SEPARATOR, $sluggedElements); + return $this->stripLast($sluggedPath); } /**