]> source.dussan.org Git - nextcloud-server.git/commitdiff
split share and root config for smb backend, also sanitize config a bit more
authorRobin Appelman <icewind@owncloud.com>
Thu, 7 Jun 2012 23:29:46 +0000 (01:29 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 10 Jul 2012 12:19:51 +0000 (14:19 +0200)
apps/files_external/lib/smb.php
apps/files_external/tests/config.php
apps/files_external/tests/smb.php

index f5e6d78e7761ab3699fc4524021cee126216d1f5..f594fbb880d951a8682f8ddce97ce72035aa7d40 100644 (file)
@@ -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;
                
        }
 }
index 35b5fa038631567169a56274013d7ffa890b95e8..1b47618e4723867fca03f7214d0f1962268d45a0 100644 (file)
@@ -34,6 +34,7 @@ return array(
                'user'=>'test',
                'password'=>'test',
                'host'=>'localhost',
-               'root'=>'/test',
+               'share'=>'/test',
+               'root'=>'/test/',
        ),
 );
index 52e1700b0191e7047794fbc3732d2d98b1bd7814..e1495b7480dfaa1ace26de23b115e6488a6bdd64 100644 (file)
@@ -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']);
                }