Skip to content

Commit

Permalink
Merge: Mkdir fix
Browse files Browse the repository at this point in the history
Calling `String::mkdir` on a path might produce errors when part of the path already existed.

This PR fixes this behaviour.

Pull-Request: #2298
Reviewed-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Aug 26, 2016
2 parents 4b08693 + 72caf7f commit f78a35b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/core/file.nit
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,12 @@ redef class Text
do
for i in substrings do s.write_native(i.to_cstring, 0, i.byte_length)
end
end

redef class String
# return true if a file with this names exists
fun file_exists: Bool do return to_cstring.file_exists
end

redef class String
# The status of a file. see POSIX stat(2).
fun file_stat: nullable FileStat
do
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f78a35b

Please sign in to comment.