lib/core: `String::mkdir` will only produce an error when the complete path already...
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 26 Aug 2016 20:13:42 +0000 (16:13 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 26 Aug 2016 20:13:42 +0000 (16:13 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/file.nit

index 2405186..dc1ccb7 100644 (file)
@@ -1216,15 +1216,21 @@ redef class String
                        path.add('/')
                end
                var error: nullable Error = null
-               for d in dirs do
+               for i in [0 .. dirs.length - 1[ do
+                       var d = dirs[i]
                        if d.is_empty then continue
                        path.append(d)
                        path.add('/')
-                       var res = path.to_s.to_cstring.file_mkdir(mode)
+                       if path.file_exists then continue
+                       var res = path.to_cstring.file_mkdir(mode)
                        if not res and error == null then
                                error = new IOError("Cannot create directory `{path}`: {sys.errno.strerror}")
                        end
                end
+               var res = self.to_cstring.file_mkdir(mode)
+               if not res and error == null then
+                       error = new IOError("Cannot create directory `{path}`: {sys.errno.strerror}")
+               end
                return error
        end