mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os,tools: add os.vtmp_dir()
Use it to consistently place all temporary files created by tests in a overridable folder specific to the user, that is easy to cleanup later. NOTE: os.temp_dir() on macos returns `/tmp`, and using `/tmp/v` is a problem when multiple unix users are trying to access/create/write to it.
This commit is contained in:
17
vlib/os/os.v
17
vlib/os/os.v
@@ -719,6 +719,23 @@ pub fn temp_dir() string {
|
||||
return path
|
||||
}
|
||||
|
||||
// vtmp_dir returns the path to a folder, that is writable to V programs, *and* specific
|
||||
// to the OS user. It can be overriden by setting the env variable `VTMP`.
|
||||
pub fn vtmp_dir() string {
|
||||
mut vtmp := getenv('VTMP')
|
||||
if vtmp.len > 0 {
|
||||
return vtmp
|
||||
}
|
||||
uid := getuid()
|
||||
vtmp = join_path_single(temp_dir(), 'v_$uid')
|
||||
if !exists(vtmp) || !is_dir(vtmp) {
|
||||
// create a new directory, that is private to the user:
|
||||
mkdir_all(vtmp, mode: 0o700) or { panic(err) }
|
||||
}
|
||||
setenv('VTMP', vtmp, true)
|
||||
return vtmp
|
||||
}
|
||||
|
||||
fn default_vmodules_path() string {
|
||||
hdir := home_dir()
|
||||
res := join_path_single(hdir, '.vmodules')
|
||||
|
||||
Reference in New Issue
Block a user