From 5874d7c5abffdbb24c10677297dd3630f20eebe1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 5 Aug 2020 09:04:40 +0300 Subject: [PATCH] os: add os.getpid(), use it in os.is_writable_folder on windows --- vlib/os/os_nix.c.v | 5 +++++ vlib/os/os_windows.c.v | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 648aa2affc..0766d2af2f 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -211,3 +211,8 @@ pub fn is_writable_folder(folder string) ?bool { os.rm(tmp_perm_check) return true } + +[inline] +pub fn getpid() int { + return C.getpid() +} diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 78f4f9bec6..270f093123 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -378,7 +378,7 @@ pub fn is_writable_folder(folder string) ?bool { if !os.is_dir(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 { 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) return true } + +fn C._getpid() int +[inline] +pub fn getpid() int { + return C._getpid() +}