diff --git a/.github/workflows/android_cross_compile.vsh b/.github/workflows/android_cross_compile.vsh index 40526bca77..764d281f28 100755 --- a/.github/workflows/android_cross_compile.vsh +++ b/.github/workflows/android_cross_compile.vsh @@ -10,7 +10,7 @@ fn main() { assert ndk.found() assert vxt.found() - work_dir := os.join_path(os.temp_dir(), 'android_cross_compile_test') + work_dir := os.join_path(os.vtmp_dir(), 'android_cross_compile_test') os.rm(work_dir) or {} os.mkdir_all(work_dir) or { panic(err) } vexe := vxt.vexe() diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 74a3e13ec9..ddb1bc1c1e 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -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 diff --git a/cmd/tools/test_if_v_test_system_works.v b/cmd/tools/test_if_v_test_system_works.v index 5af4ca8229..54cf8d00a5 100644 --- a/cmd/tools/test_if_v_test_system_works.v +++ b/cmd/tools/test_if_v_test_system_works.v @@ -26,7 +26,7 @@ fn get_vexe_path() string { } fn new_tdir() string { - dir := os.join_path(os.temp_dir(), 'v', rand.ulid()) + dir := os.join_path(os.vtmp_dir(), 'v', rand.ulid()) os.rmdir_all(dir) or {} os.mkdir_all(dir) or { panic(err) } C.atexit(cleanup_tdir) diff --git a/cmd/tools/vbump_test.v b/cmd/tools/vbump_test.v index 15b81e61fa..e091b69358 100644 --- a/cmd/tools/vbump_test.v +++ b/cmd/tools/vbump_test.v @@ -2,7 +2,7 @@ import os const vexe = @VEXE -const tfolder = os.join_path(os.temp_dir(), 'v', 'vbump') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'vbump') fn testsuite_begin() { os.mkdir_all(tfolder) or {} diff --git a/cmd/tools/vcheck-md.v b/cmd/tools/vcheck-md.v index 0227bf9b86..a114a289b2 100644 --- a/cmd/tools/vcheck-md.v +++ b/cmd/tools/vcheck-md.v @@ -21,7 +21,7 @@ const ( show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args non_option_args = cmdline.only_non_options(os.args[2..]) is_verbose = os.getenv('VERBOSE') != '' - vcheckfolder = os.join_path(os.temp_dir(), 'v', 'vcheck_$os.getuid()') + vcheckfolder = os.join_path(os.vtmp_dir(), 'v', 'vcheck_$os.getuid()') should_autofix = os.getenv('VAUTOFIX') != '' vexe = @VEXE ) diff --git a/cmd/tools/vcreate_test.v b/cmd/tools/vcreate_test.v index 5e416b4c38..9ac4764992 100644 --- a/cmd/tools/vcreate_test.v +++ b/cmd/tools/vcreate_test.v @@ -1,6 +1,6 @@ import os -const test_path = os.join_path(os.temp_dir(), 'v', 'vcreate_test') +const test_path = os.join_path(os.vtmp_dir(), 'v', 'vcreate_test') fn init_and_check() ! { os.execute_or_exit('${os.quoted_path(@VEXE)} init') diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index eced1ea280..c78e85a5bb 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -33,7 +33,7 @@ mut: const ( formatted_file_token = '\@\@\@' + 'FORMATTED_FILE: ' - vtmp_folder = util.get_vtmp_folder() + vtmp_folder = os.vtmp_dir() term_colors = term.can_show_color_on_stderr() ) diff --git a/cmd/tools/vgret.v b/cmd/tools/vgret.v index eb4b32dcb5..e322665fd5 100644 --- a/cmd/tools/vgret.v +++ b/cmd/tools/vgret.v @@ -51,7 +51,7 @@ Examples: Compare screenshots in `/tmp/src` to existing screenshots in `/tmp/dst` v gret --compare-only /tmp/src /tmp/dst ' - tmp_dir = os.join_path(os.temp_dir(), 'v', tool_name) + tmp_dir = os.join_path(os.vtmp_dir(), 'v', tool_name) runtime_os = os.user_os() v_root = os.real_path(@VMODROOT) ) @@ -271,7 +271,7 @@ fn compare_screenshots(opt Options, output_path string, target_path string) ! { if idiff_exe == '' { return error('$tool_name need the `idiff` tool installed. It can be installed on Ubuntu with `sudo apt install openimageio-tools`') } - diff_file := os.join_path(os.temp_dir(), os.file_name(src).all_before_last('.') + + diff_file := os.join_path(os.vtmp_dir(), os.file_name(src).all_before_last('.') + '.diff.tif') flags := app_config.compare.flags.join(' ') diff_cmd := '${os.quoted_path(idiff_exe)} $flags -abs -od -o ${os.quoted_path(diff_file)} -abs ${os.quoted_path(src)} ${os.quoted_path(target)}' @@ -305,18 +305,18 @@ fn compare_screenshots(opt Options, output_path string, target_path string) ! { eprintln('$fail_src != $fail_target') } first := fails.keys()[0] - fail_copy := os.join_path(os.temp_dir(), 'fail.' + first.all_after_last('.')) + fail_copy := os.join_path(os.vtmp_dir(), 'fail.' + first.all_after_last('.')) os.cp(first, fail_copy)! eprintln('First failed file `$first` is copied to `$fail_copy`') - diff_file := os.join_path(os.temp_dir(), os.file_name(first).all_before_last('.') + + diff_file := os.join_path(os.vtmp_dir(), os.file_name(first).all_before_last('.') + '.diff.tif') - diff_copy := os.join_path(os.temp_dir(), 'diff.tif') + diff_copy := os.join_path(os.vtmp_dir(), 'diff.tif') if os.is_file(diff_file) { os.cp(diff_file, diff_copy)! eprintln('First failed diff file `$diff_file` is copied to `$diff_copy`') eprintln('Removing alpha channel from $diff_copy ...') - final_fail_result_file := os.join_path(os.temp_dir(), 'diff.png') + final_fail_result_file := os.join_path(os.vtmp_dir(), 'diff.png') opt.verbose_execute('convert ${os.quoted_path(diff_copy)} -alpha off ${os.quoted_path(final_fail_result_file)}') eprintln('Final diff file: `$final_fail_result_file`') } diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 46edf4967b..0dbb921593 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -35,7 +35,7 @@ const ( is_stdin_a_pipe = os.is_atty(0) == 0 vexe = os.getenv('VEXE') vstartup = os.getenv('VSTARTUP') - repl_folder = os.join_path(os.temp_dir(), 'v', 'repl') + repl_folder = os.join_path(os.vtmp_dir(), 'v', 'repl') ) enum FnType { diff --git a/cmd/tools/vsymlink.v b/cmd/tools/vsymlink.v index 3d14db0389..5ebc2fb45a 100644 --- a/cmd/tools/vsymlink.v +++ b/cmd/tools/vsymlink.v @@ -1,6 +1,5 @@ import os import v.pref -import v.util $if windows { $if tinyc { @@ -32,7 +31,7 @@ fn main() { } fn cleanup_vtmp_folder() { - os.rmdir_all(util.get_vtmp_folder()) or {} + os.rmdir_all(os.vtmp_dir()) or {} } fn setup_symlink_github() { diff --git a/cmd/tools/vwipe-cache.v b/cmd/tools/vwipe-cache.v index cc4660ac31..4ce4ce848a 100644 --- a/cmd/tools/vwipe-cache.v +++ b/cmd/tools/vwipe-cache.v @@ -2,12 +2,10 @@ module main import os import v.vcache -import v.util fn main() { wipe_path(vcache.new_cache_manager([]).basepath, 'V cache') - wipe_path(util.get_vtmp_folder(), 'V tmp.c') - wipe_path(os.join_path(os.temp_dir(), 'v'), 'V tests') + wipe_path(os.vtmp_dir(), 'V tmp.c and tests folder') } fn wipe_path(cpath string, label string) { diff --git a/vlib/io/util/util_test.v b/vlib/io/util/util_test.v index 261afb3f50..df9fdc063a 100644 --- a/vlib/io/util/util_test.v +++ b/vlib/io/util/util_test.v @@ -5,7 +5,7 @@ const ( // tfolder will contain all the temporary files/subfolders made by // the different tests. It would be removed in testsuite_end(), so // individual os tests do not need to clean up after themselves. - tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'io_util_test') + tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'io_util_test') ) fn testsuite_begin() { diff --git a/vlib/net/unix/unix_test.v b/vlib/net/unix/unix_test.v index 0813cb9959..547f810434 100644 --- a/vlib/net/unix/unix_test.v +++ b/vlib/net/unix/unix_test.v @@ -1,7 +1,7 @@ import os import net.unix -const tfolder = os.join_path(os.temp_dir(), 'v', 'unix_test') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'unix_test') const test_port = os.join_path(tfolder, 'unix_domain_socket') diff --git a/vlib/net/unix/use_net_and_net_unix_together_test.v b/vlib/net/unix/use_net_and_net_unix_together_test.v index 85f277d34d..5ff7a8ba53 100644 --- a/vlib/net/unix/use_net_and_net_unix_together_test.v +++ b/vlib/net/unix/use_net_and_net_unix_together_test.v @@ -5,7 +5,7 @@ import net // ensure that `net` is used, i.e. no warnings const use_net = net.no_timeout -const tfolder = os.join_path(os.temp_dir(), 'v', 'net_and_unix_together') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'net_and_unix_together') const test_port = os.join_path(tfolder, 'unix_domain_socket') diff --git a/vlib/orm/orm_sql_or_blocks_test.v b/vlib/orm/orm_sql_or_blocks_test.v index 4c4fa5250a..f0d349e0db 100644 --- a/vlib/orm/orm_sql_or_blocks_test.v +++ b/vlib/orm/orm_sql_or_blocks_test.v @@ -6,7 +6,7 @@ struct User { name string [unique] } -const db_folder = os.join_path(os.temp_dir(), 'v', 'orm_sql') +const db_folder = os.join_path(os.vtmp_dir(), 'v', 'orm_sql') const db_path = os.join_path(db_folder, 'sql_statement_or_blocks.db') diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 7746a1e829..8da14b71af 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -1,6 +1,6 @@ import os -const tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'os_file_test') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'os_file_test') const tfile = os.join_path_single(tfolder, 'test_file') diff --git a/vlib/os/find_abs_path_of_executable_test.v b/vlib/os/find_abs_path_of_executable_test.v index 495ef51df6..334b0fc543 100644 --- a/vlib/os/find_abs_path_of_executable_test.v +++ b/vlib/os/find_abs_path_of_executable_test.v @@ -1,46 +1,46 @@ -module os +import os fn test_find_abs_path_of_executable() { - tfolder := join_path(temp_dir(), 'v', 'tests', 'filepath_test') - rmdir_all(tfolder) or {} - assert !is_dir(tfolder) - mkdir_all(tfolder)? + tfolder := os.join_path(os.vtmp_dir(), 'v', 'tests', 'filepath_test') + os.rmdir_all(tfolder) or {} + assert !os.is_dir(tfolder) + os.mkdir_all(tfolder)! defer { - rmdir_all(tfolder) or {} + os.rmdir_all(tfolder) or {} } // - original_path := getenv('PATH') - original_wdir := getwd() + original_path := os.getenv('PATH') + original_wdir := os.getwd() defer { - chdir(original_wdir) or {} + os.chdir(original_wdir) or {} } // - new_path := tfolder + path_delimiter + original_path - setenv('PATH', new_path, true) + new_path := tfolder + os.path_delimiter + original_path + os.setenv('PATH', new_path, true) // mut myclang_file := 'myclang' $if windows { myclang_file += '.bat' } // - chdir(tfolder)? - write_file(myclang_file, 'echo hello')? - chmod(myclang_file, 0o0777)! - dump(real_path(myclang_file)) - dump(is_executable(myclang_file)) + os.chdir(tfolder)! + os.write_file(myclang_file, 'echo hello')! + os.chmod(myclang_file, 0o0777)! + dump(os.real_path(myclang_file)) + dump(os.is_executable(myclang_file)) defer { - rm(myclang_file) or {} + os.rm(myclang_file) or {} } // - fpath := find_abs_path_of_executable('myclang') or { + fpath := os.find_abs_path_of_executable('myclang') or { assert false return } dump(fpath) // - setenv('PATH', original_path, true) - chdir(home_dir())! // change to a *completely* different folder, to avoid the original PATH containing `.` - if x := find_abs_path_of_executable('myclang') { + os.setenv('PATH', original_path, true) + os.chdir(os.home_dir())! // change to a *completely* different folder, to avoid the original PATH containing `.` + if x := os.find_abs_path_of_executable('myclang') { eprintln('> find_abs_path_of_executable should have failed, but instead it found: $x') assert false } diff --git a/vlib/os/inode.c.v b/vlib/os/inode.c.v index 0c8296c320..a82086416f 100644 --- a/vlib/os/inode.c.v +++ b/vlib/os/inode.c.v @@ -3,7 +3,7 @@ // that can be found in the LICENSE file. module os -enum FileType { +pub enum FileType { regular directory character_device diff --git a/vlib/os/inode_test.v b/vlib/os/inode_test.v index eaa31852bc..4bb1093b79 100644 --- a/vlib/os/inode_test.v +++ b/vlib/os/inode_test.v @@ -1,56 +1,56 @@ -module os +import os const ( // tfolder will contain all the temporary files/subfolders made by // the different tests. It would be removed in testsuite_end(), so // individual os tests do not need to clean up after themselves. - tfolder = join_path(temp_dir(), 'v', 'tests', 'inode_test') + tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'inode_test') ) fn testsuite_begin() { - eprintln('testsuite_begin, tfolder = $os.tfolder') - rmdir_all(os.tfolder) or {} - assert !is_dir(os.tfolder) - mkdir_all(os.tfolder) or { panic(err) } - chdir(os.tfolder) or {} - assert is_dir(os.tfolder) + eprintln('testsuite_begin, tfolder = $tfolder') + os.rmdir_all(tfolder) or {} + assert !os.is_dir(tfolder) + os.mkdir_all(tfolder) or { panic(err) } + os.chdir(tfolder) or {} + assert os.is_dir(tfolder) } fn testsuite_end() { - chdir(wd_at_startup) or {} - rmdir_all(os.tfolder) or { panic(err) } - assert !is_dir(os.tfolder) + os.chdir(os.wd_at_startup) or {} + os.rmdir_all(tfolder) or { panic(err) } + assert !os.is_dir(tfolder) } fn test_inode_file_type() { filename := './test1.txt' - mut file := open_file(filename, 'w', 0o600) or { return } + mut file := os.open_file(filename, 'w', 0o600) or { return } file.close() - mode := inode(filename) - rm(filename) or { panic(err) } + mode := os.inode(filename) + os.rm(filename) or { panic(err) } assert mode.typ == .regular } fn test_inode_file_owner_permission() { filename := './test2.txt' - mut file := open_file(filename, 'w', 0o600) or { return } + mut file := os.open_file(filename, 'w', 0o600) or { return } file.close() - mode := inode(filename) - rm(filename) or {} + mode := os.inode(filename) + os.rm(filename) or {} assert mode.owner.read assert mode.owner.write assert !mode.owner.execute } fn test_inode_file_permissions_bitmask() { - if user_os() == 'windows' { + if os.user_os() == 'windows' { println('> skipping ${@FN} on windows') return } filename := './test3.txt' - mut file := open_file(filename, 'w', 0o641) or { return } + mut file := os.open_file(filename, 'w', 0o641) or { return } file.close() - mode := inode(filename) - rm(filename) or {} + mode := os.inode(filename) + os.rm(filename) or {} assert mode.bitmask() == 0o641 } diff --git a/vlib/os/os.v b/vlib/os/os.v index 6bac8af978..d24f524181 100644 --- a/vlib/os/os.v +++ b/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') diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 668ef27af1..a37bec6214 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -5,7 +5,7 @@ const ( // tfolder will contain all the temporary files/subfolders made by // the different tests. It would be removed in testsuite_end(), so // individual os tests do not need to clean up after themselves. - tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'os_test') + tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'os_test') ) // os.args has to be *already initialized* with the program's argc/argv at this point diff --git a/vlib/os/process_test.v b/vlib/os/process_test.v index 8a44f5d4f7..7c45b75f21 100644 --- a/vlib/os/process_test.v +++ b/vlib/os/process_test.v @@ -6,7 +6,7 @@ import time const ( vexe = os.getenv('VEXE') vroot = os.dir(vexe) - tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'os_process') + tfolder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'os_process') test_os_process = os.join_path(tfolder, 'test_os_process.exe') test_os_process_source = os.join_path(vroot, 'cmd/tools/test_os_process.v') ) diff --git a/vlib/stbi/stbi_test.v b/vlib/stbi/stbi_test.v index e9fe1ef2c5..55933aea51 100644 --- a/vlib/stbi/stbi_test.v +++ b/vlib/stbi/stbi_test.v @@ -1,7 +1,7 @@ import os import stbi -const tfolder = os.join_path(os.temp_dir(), 'v', 'stbi') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'stbi') fn testsuite_begin() { os.mkdir_all(tfolder) or {} diff --git a/vlib/toml/tests/alexcrichton.toml-rs-tests_test.v b/vlib/toml/tests/alexcrichton.toml-rs-tests_test.v index abd899dc19..c19501e755 100644 --- a/vlib/toml/tests/alexcrichton.toml-rs-tests_test.v +++ b/vlib/toml/tests/alexcrichton.toml-rs-tests_test.v @@ -37,7 +37,7 @@ const ( ] tests_folder = os.join_path('test-suite', 'tests') jq = os.find_abs_path_of_executable('jq') or { '' } - compare_work_dir_root = os.join_path(os.temp_dir(), 'v', 'toml', 'alexcrichton') + compare_work_dir_root = os.join_path(os.vtmp_dir(), 'v', 'toml', 'alexcrichton') // From: https://stackoverflow.com/a/38266731/1904615 jq_normalize = r'# Apply f to composite entities recursively using keys[], and to atoms def sorted_walk(f): diff --git a/vlib/toml/tests/burntsushi.toml-test_test.v b/vlib/toml/tests/burntsushi.toml-test_test.v index b066be6117..931563adb6 100644 --- a/vlib/toml/tests/burntsushi.toml-test_test.v +++ b/vlib/toml/tests/burntsushi.toml-test_test.v @@ -27,7 +27,7 @@ const ( //'integer/long.toml', // TODO https://github.com/vlang/v/issues/9507 jq = os.find_abs_path_of_executable('jq') or { '' } - compare_work_dir_root = os.join_path(os.temp_dir(), 'v', 'toml', 'burntsushi') + compare_work_dir_root = os.join_path(os.vtmp_dir(), 'v', 'toml', 'burntsushi') // From: https://stackoverflow.com/a/38266731/1904615 jq_normalize = r'# Apply f to composite entities recursively using keys[], and to atoms def sorted_walk(f): diff --git a/vlib/toml/tests/iarna.toml-spec-tests_test.v b/vlib/toml/tests/iarna.toml-spec-tests_test.v index 5541914c31..b06e92cf19 100644 --- a/vlib/toml/tests/iarna.toml-spec-tests_test.v +++ b/vlib/toml/tests/iarna.toml-spec-tests_test.v @@ -43,7 +43,7 @@ const ( jq = os.find_abs_path_of_executable('jq') or { '' } python = os.find_abs_path_of_executable('python') or { '' } - compare_work_dir_root = os.join_path(os.temp_dir(), 'v', 'toml', 'iarna') + compare_work_dir_root = os.join_path(os.vtmp_dir(), 'v', 'toml', 'iarna') // From: https://stackoverflow.com/a/38266731/1904615 jq_normalize = r'# Apply f to composite entities recursively using keys[], and to atoms def sorted_walk(f): diff --git a/vlib/toml/tests/toml_test.v b/vlib/toml/tests/toml_test.v index d31e923840..371cdbef53 100644 --- a/vlib/toml/tests/toml_test.v +++ b/vlib/toml/tests/toml_test.v @@ -68,7 +68,7 @@ fn test_toml() { } fn test_toml_file() { - out_path := os.join_path(os.temp_dir(), 'v', 'toml_tests') + out_path := os.join_path(os.vtmp_dir(), 'v', 'toml_tests') test_file := os.join_path(out_path, 'toml_example.toml') os.mkdir_all(out_path) or { assert false } defer { diff --git a/vlib/v/builder/builder_test.v b/vlib/v/builder/builder_test.v index 43d22eec73..ab392686dc 100644 --- a/vlib/v/builder/builder_test.v +++ b/vlib/v/builder/builder_test.v @@ -2,7 +2,7 @@ module main import os -const test_path = os.join_path(os.temp_dir(), 'v', 'run_check') +const test_path = os.join_path(os.vtmp_dir(), 'v', 'run_check') const vexe = @VEXE diff --git a/vlib/v/builder/interpreterbuilder/v_interpret_test.v b/vlib/v/builder/interpreterbuilder/v_interpret_test.v index ca6b8c2b31..e647832cc2 100644 --- a/vlib/v/builder/interpreterbuilder/v_interpret_test.v +++ b/vlib/v/builder/interpreterbuilder/v_interpret_test.v @@ -9,7 +9,7 @@ fn interpreter_wrap(a string) string { } fn interp_test(expression string, expected string) ! { - tmpdir := os.join_path(os.temp_dir(), 'v', 'interpret_test_$rand.ulid()') + tmpdir := os.join_path(os.vtmp_dir(), 'v', 'interpret_test_$rand.ulid()') os.mkdir_all(tmpdir) or {} defer { os.rmdir_all(tmpdir) or {} diff --git a/vlib/v/builder/rebuilding.v b/vlib/v/builder/rebuilding.v index addbb43132..fecd0571e9 100644 --- a/vlib/v/builder/rebuilding.v +++ b/vlib/v/builder/rebuilding.v @@ -358,7 +358,7 @@ pub fn (mut b Builder) rebuild(backend_cb FnBackend) { } pub fn (mut b Builder) get_vtmp_filename(base_file_name string, postfix string) string { - vtmp := util.get_vtmp_folder() + vtmp := os.vtmp_dir() mut uniq := '' if !b.pref.reuse_tmpc { uniq = '.$rand.u64()' diff --git a/vlib/v/gen/c/coutput_test.v b/vlib/v/gen/c/coutput_test.v index c86c1f992c..e3a6f47d2c 100644 --- a/vlib/v/gen/c/coutput_test.v +++ b/vlib/v/gen/c/coutput_test.v @@ -21,7 +21,7 @@ fn mm(s string) string { fn test_out_files() { println(term.colorize(term.green, '> testing whether .out files match:')) os.chdir(vroot) or {} - output_path := os.join_path(os.temp_dir(), 'v', 'coutput', 'out') + output_path := os.join_path(os.vtmp_dir(), 'v', 'coutput', 'out') os.mkdir_all(output_path)! defer { os.rmdir_all(output_path) or {} @@ -92,7 +92,7 @@ fn test_out_files() { fn test_c_must_have_files() { println(term.colorize(term.green, '> testing whether `.c.must_have` files match:')) os.chdir(vroot) or {} - output_path := os.join_path(os.temp_dir(), 'v', 'coutput', 'c_must_have') + output_path := os.join_path(os.vtmp_dir(), 'v', 'coutput', 'c_must_have') os.mkdir_all(output_path)! defer { os.rmdir_all(output_path) or {} diff --git a/vlib/v/gen/golang/tests/golang_test.v b/vlib/v/gen/golang/tests/golang_test.v index db577021b1..dfda3b7c13 100644 --- a/vlib/v/gen/golang/tests/golang_test.v +++ b/vlib/v/gen/golang/tests/golang_test.v @@ -19,7 +19,7 @@ fn test_golang() { dir := os.join_path(vroot, 'vlib/v/gen/golang/tests') files := os.ls(dir) or { panic(err) } // - wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'golang') + wrkdir := os.join_path(os.vtmp_dir(), 'v', 'tests', 'golang') os.mkdir_all(wrkdir) or { panic(err) } defer { os.rmdir_all(wrkdir) or {} diff --git a/vlib/v/gen/js/jsgen_test.v b/vlib/v/gen/js/jsgen_test.v index 70ef00dab8..15ec1d9cf4 100644 --- a/vlib/v/gen/js/jsgen_test.v +++ b/vlib/v/gen/js/jsgen_test.v @@ -2,7 +2,7 @@ import os const ( test_dir = os.join_path('vlib', 'v', 'gen', 'js', 'tests') - output_dir = os.join_path(os.temp_dir(), 'v', '_js_tests/') + output_dir = os.join_path(os.vtmp_dir(), 'v', '_js_tests/') v_options = '-b js -w' node_options = '' ) diff --git a/vlib/v/gen/native/tests/native_test.v b/vlib/v/gen/native/tests/native_test.v index 649858b36a..b99cc572fd 100644 --- a/vlib/v/gen/native/tests/native_test.v +++ b/vlib/v/gen/native/tests/native_test.v @@ -20,7 +20,7 @@ fn test_native() { dir := os.join_path(vroot, 'vlib/v/gen/native/tests') files := os.ls(dir) or { panic(err) } // - wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'native') + wrkdir := os.join_path(os.vtmp_dir(), 'v', 'tests', 'native') os.mkdir_all(wrkdir) or { panic(err) } defer { os.rmdir_all(wrkdir) or {} diff --git a/vlib/v/live/live_test.v b/vlib/v/live/live_test.v index fd878a25a7..a48c1ee4f1 100644 --- a/vlib/v/live/live_test.v +++ b/vlib/v/live/live_test.v @@ -33,7 +33,7 @@ TODO: Cleanup this when/if v has better process control/communication primitives */ const ( vexe = os.getenv('VEXE') - vtmp_folder = os.join_path(os.temp_dir(), 'v', 'tests', 'live') + vtmp_folder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'live') tmp_file = os.join_path(vtmp_folder, 'generated_live_program.tmp.v') source_file = os.join_path(vtmp_folder, 'generated_live_program.v') genexe_file = os.join_path(vtmp_folder, 'generated_live_program') diff --git a/vlib/v/pkgconfig/bin/pkgconfig_test.v b/vlib/v/pkgconfig/bin/pkgconfig_test.v index 7b58f15d6e..c8fe35fb1e 100644 --- a/vlib/v/pkgconfig/bin/pkgconfig_test.v +++ b/vlib/v/pkgconfig/bin/pkgconfig_test.v @@ -5,7 +5,7 @@ const vexe = os.getenv('VEXE') const vroot = os.dir(vexe) fn test_pkgconfig_can_be_compiled() { - tmp_exe := os.join_path(os.temp_dir(), '${os.getpid()}_pkgconfig.exe') + tmp_exe := os.join_path(os.vtmp_dir(), '${os.getpid()}_pkgconfig.exe') pkgconfig_v_file := os.real_path(os.join_path(vroot, 'vlib/v/pkgconfig/bin/pkgconfig.v')) assert !os.exists(tmp_exe) res := os.system('${os.quoted_path(vexe)} -o ${os.quoted_path(tmp_exe)} ${os.quoted_path(pkgconfig_v_file)}') @@ -13,5 +13,5 @@ fn test_pkgconfig_can_be_compiled() { assert false } assert os.exists(tmp_exe) - os.rm(tmp_exe)? + os.rm(tmp_exe)! } diff --git a/vlib/v/pref/options_test.v b/vlib/v/pref/options_test.v index 04ecc3d03e..6a32ba80bb 100644 --- a/vlib/v/pref/options_test.v +++ b/vlib/v/pref/options_test.v @@ -5,7 +5,7 @@ import time const vexe = @VEXE -const tfolder = os.join_path(os.temp_dir(), 'v', 'custom_compile') +const tfolder = os.join_path(os.vtmp_dir(), 'v', 'custom_compile') fn testsuite_begin() { os.mkdir_all(tfolder) or {} diff --git a/vlib/v/tests/closure_generator_test.v b/vlib/v/tests/closure_generator_test.v index b0ca7f9acb..09ed320f65 100644 --- a/vlib/v/tests/closure_generator_test.v +++ b/vlib/v/tests/closure_generator_test.v @@ -162,7 +162,7 @@ fn test_closure_return_${styp}_${i}() ? { code := v_code.str() println('Compiling V code (${code.count('\n')} lines) ...') - wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'closures') + wrkdir := os.join_path(os.vtmp_dir(), 'v', 'tests', 'closures') os.mkdir_all(wrkdir)? os.chdir(wrkdir)? os.write_file('closure_return_test.v', code)? diff --git a/vlib/v/tests/crun_mode/crun_test.v b/vlib/v/tests/crun_mode/crun_test.v index 728eb192f0..0b3703c71d 100644 --- a/vlib/v/tests/crun_mode/crun_test.v +++ b/vlib/v/tests/crun_mode/crun_test.v @@ -1,7 +1,7 @@ import os import time -const crun_folder = os.join_path(os.temp_dir(), 'v', 'crun_folder') +const crun_folder = os.join_path(os.vtmp_dir(), 'v', 'crun_folder') const vprogram_file = os.join_path(crun_folder, 'vprogram.vv') diff --git a/vlib/v/tests/run_v_code_from_stdin_test.v b/vlib/v/tests/run_v_code_from_stdin_test.v index 7ec16d653a..c0c2414c56 100644 --- a/vlib/v/tests/run_v_code_from_stdin_test.v +++ b/vlib/v/tests/run_v_code_from_stdin_test.v @@ -4,13 +4,13 @@ const vexe = os.getenv('VEXE') const turn_off_vcolors = os.setenv('VCOLORS', 'never', true) -const vtmp_folder = os.join_path(os.temp_dir(), 'v', 'tests', 'run_v_code') +const vtmp_folder = os.join_path(os.vtmp_dir(), 'v', 'tests', 'run_v_code') fn test_vexe_is_set() { assert vexe != '' } -fn pipe_to_v_run() ? { +fn pipe_to_v_run() ! { os.mkdir_all(vtmp_folder) or {} defer { os.rmdir_all(vtmp_folder) or {} @@ -18,7 +18,7 @@ fn pipe_to_v_run() ? { cat_cmd := if os.user_os() == 'windows' { 'cmd /c type' } else { 'cat' } tmp_v_file := os.join_path(os.real_path(vtmp_folder), 'generated_piped_program.v') // eprintln('>>> tmp_v_file: $tmp_v_file') - os.write_file(tmp_v_file, 'println(1 + 3)\nprintln("hello")\n')? + os.write_file(tmp_v_file, 'println(1 + 3)\nprintln("hello")\n')! assert os.is_file(tmp_v_file) cmd := '$cat_cmd ${os.quoted_path(tmp_v_file)} | ${os.quoted_path(vexe)} run -' res := os.execute(cmd) diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index 4b7ec0a4d9..82b393e65f 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -66,7 +66,7 @@ fn test_all() { mut files := os.ls(dir) or { panic(err) } files.sort() // - wrkdir := os.join_path(os.temp_dir(), 'v', 'tests', 'valgrind') + wrkdir := os.join_path(os.vtmp_dir(), 'v', 'tests', 'valgrind') os.mkdir_all(wrkdir) or { panic(err) } os.chdir(wrkdir) or {} // diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 5e69155e43..0a5ea4becd 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -488,18 +488,10 @@ pub fn recompile_file(vexe string, file string) { } } +// get_vtmp_folder returns the path to a folder, that is writable to V programs, +// and specific to the user. It can be overriden by setting the env variable `VTMP`. pub fn get_vtmp_folder() string { - mut vtmp := os.getenv('VTMP') - if vtmp.len > 0 { - return vtmp - } - uid := os.getuid() - vtmp = os.join_path_single(os.temp_dir(), 'v_$uid') - if !os.exists(vtmp) || !os.is_dir(vtmp) { - os.mkdir_all(vtmp, mode: 0o700) or { panic(err) } // keep directory private - } - os.setenv('VTMP', vtmp, true) - return vtmp + return os.vtmp_dir() } pub fn should_bundle_module(mod string) bool { diff --git a/vlib/v/vcache/vcache_test.v b/vlib/v/vcache/vcache_test.v index f7e064eab0..23e221eadb 100644 --- a/vlib/v/vcache/vcache_test.v +++ b/vlib/v/vcache/vcache_test.v @@ -2,7 +2,7 @@ import os import v.vcache const ( - vcache_folder = os.join_path(os.temp_dir(), 'v', 'cache_folder') + vcache_folder = os.join_path(os.vtmp_dir(), 'v', 'cache_folder') ) fn check_cache_entry_fpath_invariants(x string, extension string) { diff --git a/vlib/vweb/assets/assets_test.v b/vlib/vweb/assets/assets_test.v index b9b804c778..0de49bac27 100644 --- a/vlib/vweb/assets/assets_test.v +++ b/vlib/vweb/assets/assets_test.v @@ -1,7 +1,7 @@ import vweb.assets import os -const base_cache_dir = os.join_path(os.temp_dir(), 'v', 'assets_test_cache') +const base_cache_dir = os.join_path(os.vtmp_dir(), 'v', 'assets_test_cache') fn testsuite_begin() { os.mkdir_all(base_cache_dir) or {}