@@ -47,7 +47,7 @@ function __construct(IShare $share, $prefix = null)
4747 */
4848 public function write ($ path , $ contents , Config $ config )
4949 {
50- $ this ->createDir (Util::dirname ($ path ), $ config );
50+ $ this ->recursiveCreateDir (Util::dirname ($ path ));
5151
5252 $ location = $ this ->applyPathPrefix ($ path );
5353 $ stream = $ this ->share ->write ($ location );
@@ -71,7 +71,7 @@ public function write($path, $contents, Config $config)
7171 */
7272 public function writeStream ($ path , $ resource , Config $ config )
7373 {
74- $ this ->createDir (Util::dirname ($ path ), $ config );
74+ $ this ->recursiveCreateDir (Util::dirname ($ path ));
7575
7676 $ location = $ this ->applyPathPrefix ($ path );
7777 $ stream = $ this ->share ->write ($ location );
@@ -120,6 +120,8 @@ public function updateStream($path, $resource, Config $config)
120120 */
121121 public function rename ($ path , $ newPath )
122122 {
123+ $ this ->recursiveCreateDir (Util::dirname ($ newPath ));
124+
123125 $ location = $ this ->applyPathPrefix ($ path );
124126 $ destination = $ this ->applyPathPrefix ($ newPath );
125127
@@ -187,23 +189,31 @@ public function deleteDir($path)
187189 */
188190 public function createDir ($ path , Config $ config )
189191 {
190- $ result = compact ('path ' );
192+ $ this ->recursiveCreateDir ($ path );
193+
194+ return compact ('path ' );
195+ }
191196
197+ /**
198+ * Recursively create directories.
199+ *
200+ * @param $path
201+ */
202+ protected function recursiveCreateDir ($ path )
203+ {
192204 if ($ this ->isDirectory ($ path )) {
193- return $ result ;
205+ return ;
194206 }
195207
196208 $ directories = explode ($ this ->pathSeparator , $ path );
197209 if (count ($ directories ) > 1 ) {
198210 $ parentDirectories = array_splice ($ directories , 0 , count ($ directories ) - 1 );
199- $ this ->createDir (implode ($ this ->pathSeparator , $ parentDirectories ), $ config );
211+ $ this ->recursiveCreateDir (implode ($ this ->pathSeparator , $ parentDirectories ));
200212 }
201213
202214 $ location = $ this ->applyPathPrefix ($ path );
203215
204216 $ this ->share ->mkdir ($ location );
205-
206- return $ result ;
207217 }
208218
209219 /**
@@ -425,12 +435,12 @@ protected function deleteContents($path)
425435 */
426436 protected function isDirectory ($ path )
427437 {
428- if (empty ($ path )) {
438+ $ location = $ this ->applyPathPrefix ($ path );
439+
440+ if (empty ($ location )) {
429441 return true ;
430442 }
431443
432- $ location = $ this ->applyPathPrefix ($ path );
433-
434444 try {
435445 $ file = $ this ->share ->stat ($ location );
436446 } catch (NotFoundException $ e ) {
0 commit comments