From: Robin Appelman Date: Thu, 7 Jun 2012 23:29:46 +0000 (+0200) Subject: split share and root config for smb backend, also sanitize config a bit more X-Git-Tag: v4.5.0beta1~74^2~423^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4768510923f6bfa3f3473874395a7a61872f1df0;p=nextcloud-server.git split share and root config for smb backend, also sanitize config a bit more --- diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index f5e6d78e776..f594fbb880d 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -13,6 +13,7 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $user; private $host; private $root; + private $share; private static $tempFiles=array(); @@ -20,17 +21,32 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ $this->host=$params['host']; $this->user=$params['user']; $this->password=$params['password']; + $this->share=$params['share']; $this->root=isset($params['root'])?$params['root']:'/'; + if(substr($this->root,-1,1)!='/'){ + $this->root.='/'; + } + if(substr($this->root,0,1)!='/'){ + $this->root='/'.$this->root; + } + if(substr($this->share,0,1)!='/'){ + $this->share='/'.$this->share; + } + if(substr($this->share,-1,1)=='/'){ + $this->share=substr($this->share,0,-1); + } //create the root folder if necesary - $this->mkdir(''); + if(!$this->is_dir('')){ + $this->mkdir(''); + } } public function constructUrl($path){ if(substr($path,-1)=='/'){ $path=substr($path,0,-1); } - return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path; + return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->share.$this->root.$path; } } diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php index 970008d642c..e58a87fabdf 100644 --- a/apps/files_external/tests/config.php +++ b/apps/files_external/tests/config.php @@ -34,7 +34,8 @@ return array( 'user'=>'test', 'password'=>'test', 'host'=>'localhost', - 'root'=>'/test', + 'share'=>'/test', + 'root'=>'/test/', ), 'amazons3'=>array( 'run'=>false, diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index 52e1700b019..e1495b7480d 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/smb.php @@ -19,7 +19,7 @@ if(!is_array($config) or !isset($config['smb']) or !$config['smb']['run']){ public function setUp(){ $id=uniqid(); $this->config=include('apps/files_external/tests/config.php'); - $this->config['smb']['root'].='/'.$id;//make sure we have an new empty folder to work in + $this->config['smb']['root'].=$id;//make sure we have an new empty folder to work in $this->instance=new OC_Filestorage_SMB($this->config['smb']); }