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

os: add an optional "mode" parameter to os.mkdir and os.mkdir_all (#14887)

This commit is contained in:
Markus F.X.J. Oberhumer
2022-06-30 12:49:47 +02:00
committed by GitHub
parent 7c3571b274
commit 74bb5ae17a
8 changed files with 16 additions and 12 deletions

View File

@@ -622,8 +622,13 @@ pub fn log(s string) {
println('os.log: ' + s)
}
[params]
pub struct MkdirParams {
mode u32 = 0o777 // note that the actual mode is affected by the process's umask
}
// mkdir_all will create a valid full path of all directories given in `path`.
pub fn mkdir_all(opath string) ? {
pub fn mkdir_all(opath string, params MkdirParams) ? {
path := opath.replace('/', path_separator)
mut p := if path.starts_with(path_separator) { path_separator } else { '' }
path_parts := path.trim_left(path_separator).split(path_separator)
@@ -632,7 +637,7 @@ pub fn mkdir_all(opath string) ? {
if exists(p) && is_dir(p) {
continue
}
mkdir(p) or { return error('folder: $p, error: $err') }
mkdir(p, params) or { return error('folder: $p, error: $err') }
}
}