mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: cleanup APIs returning !bool
to either return !
or bool
(#16111)
This commit is contained in:
@ -19,7 +19,7 @@ pub fn temp_file(tfo TempFileOptions) !(os.File, string) {
|
||||
if d == '' {
|
||||
d = os.temp_dir()
|
||||
}
|
||||
os.is_writable_folder(d) or {
|
||||
os.ensure_folder_is_writable(d) or {
|
||||
return error(@FN +
|
||||
' could not create temporary file in "$d". Please ensure write permissions.')
|
||||
}
|
||||
@ -46,31 +46,28 @@ pub struct TempDirOptions {
|
||||
pattern string
|
||||
}
|
||||
|
||||
fn error_for_temporary_folder(fn_name string, d string) !string {
|
||||
return error('$fn_name could not create temporary directory "$d". Please ensure you have write permissions for it.')
|
||||
}
|
||||
|
||||
// temp_dir returns an uniquely named, writable, directory path
|
||||
pub fn temp_dir(tdo TempFileOptions) !string {
|
||||
mut d := tdo.path
|
||||
if d == '' {
|
||||
d = os.temp_dir()
|
||||
}
|
||||
os.is_writable_folder(d) or {
|
||||
return error(@FN +
|
||||
' could not create temporary directory "$d". Please ensure write permissions.')
|
||||
}
|
||||
os.ensure_folder_is_writable(d) or { return error_for_temporary_folder(@FN, d) }
|
||||
d = d.trim_right(os.path_separator)
|
||||
prefix, suffix := prefix_and_suffix(tdo.pattern) or { return error(@FN + ' $err.msg()') }
|
||||
for retry := 0; retry < util.retries; retry++ {
|
||||
path := os.join_path(d, prefix + random_number() + suffix)
|
||||
os.mkdir_all(path) or { continue }
|
||||
if os.is_dir(path) && os.exists(path) {
|
||||
os.is_writable_folder(path) or {
|
||||
return error(@FN +
|
||||
' could not create temporary directory "$d". Please ensure write permissions.')
|
||||
}
|
||||
os.ensure_folder_is_writable(path) or { return error_for_temporary_folder(@FN, d) }
|
||||
return path
|
||||
}
|
||||
}
|
||||
return error(@FN +
|
||||
' could not create temporary directory "$d". Retry limit ($util.retries) exhausted. Please ensure write permissions.')
|
||||
return error('${@FN} could not create temporary directory "$d". Retry limit ($util.retries) exhausted.')
|
||||
}
|
||||
|
||||
// * Utility functions
|
||||
|
Reference in New Issue
Block a user