1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: mkdir() error handling

This commit is contained in:
Don Alfons Nisnoni
2019-11-24 00:55:18 +08:00
committed by Alexander Medvednikov
parent 0fb0c43c0a
commit 3a6ccf7f31
12 changed files with 32 additions and 32 deletions

View File

@ -131,14 +131,14 @@ pub fn dir_exists(path string) bool {
}
// mkdir creates a new directory with the specified path.
pub fn mkdir(path string) {
_path := path.replace('/', '\\')
// Windows doesnt recursively create the folders
// so we need to help it out here
if _path.last_index('\\') != -1 {
mkdir(_path.all_before_last('\\'))
pub fn mkdir(path string) ?bool {
if path == '.' { return true }
apath := os.realpath( path )
r := int(C.CreateDirectory(apath.to_wide(), 0))
if r == 0 {
return error('mkdir failed for "$apath", because CreateDirectory returned ' + get_error_msg(int(C.GetLastError())))
}
C.CreateDirectory(_path.to_wide(), 0)
return true
}
// Ref - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=vs-2019