os: add os.getpid(), use it in os.is_writable_folder on windows

pull/6068/head
Delyan Angelov 2020-08-05 09:04:40 +03:00
parent 7b1944c2da
commit 5874d7c5ab
2 changed files with 12 additions and 1 deletions

View File

@ -211,3 +211,8 @@ pub fn is_writable_folder(folder string) ?bool {
os.rm(tmp_perm_check) os.rm(tmp_perm_check)
return true return true
} }
[inline]
pub fn getpid() int {
return C.getpid()
}

View File

@ -378,7 +378,7 @@ pub fn is_writable_folder(folder string) ?bool {
if !os.is_dir(folder) { if !os.is_dir(folder) {
return error('`folder` is not a folder') return error('`folder` is not a folder')
} }
tmp_perm_check := os.join_path(folder, 'tmp_perm_check') tmp_perm_check := os.join_path(folder, 'tmp_perm_check_pid_' + getpid().str())
mut f := os.open_file(tmp_perm_check, 'w+', 0o700) or { mut f := os.open_file(tmp_perm_check, 'w+', 0o700) or {
return error('cannot write to folder $folder: $err') return error('cannot write to folder $folder: $err')
} }
@ -386,3 +386,9 @@ pub fn is_writable_folder(folder string) ?bool {
os.rm(tmp_perm_check) os.rm(tmp_perm_check)
return true return true
} }
fn C._getpid() int
[inline]
pub fn getpid() int {
return C._getpid()
}