1
0
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:
Delyan Angelov
2022-11-03 09:24:52 +02:00
parent 509f5c7db3
commit f427a5241a
44 changed files with 114 additions and 105 deletions

View File

@ -597,9 +597,12 @@ pub fn header(msg string) {
flush_stdout()
}
// setup_new_vtmp_folder creates a new nested folder inside VTMP, then resets VTMP to it,
// so that V programs/tests will write their temporary files to new location.
// The new nested folder, and its contents, will get removed after all tests/programs succeed.
pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now()
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'tsession_${sync.thread_id().hex()}_$now')
new_vtmp_dir := os.join_path(os.vtmp_dir(), 'tsession_${sync.thread_id().hex()}_$now')
os.mkdir_all(new_vtmp_dir) or { panic(err) }
os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir