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
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
44 changed files with 114 additions and 105 deletions

View File

@ -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()

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

View File

@ -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)

View File

@ -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 {}

View File

@ -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
)

View File

@ -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')

View File

@ -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()
)

View File

@ -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`')
}

View File

@ -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 {

View File

@ -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() {

View File

@ -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) {

View File

@ -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() {

View File

@ -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')

View File

@ -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')

View File

@ -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')

View File

@ -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')

View File

@ -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
}

View File

@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
module os
enum FileType {
pub enum FileType {
regular
directory
character_device

View File

@ -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
}

View File

@ -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')

View File

@ -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

View File

@ -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')
)

View File

@ -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 {}

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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 {

View File

@ -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

View File

@ -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 {}

View File

@ -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()'

View File

@ -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 {}

View File

@ -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 {}

View File

@ -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 = ''
)

View File

@ -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 {}

View File

@ -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')

View File

@ -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)!
}

View File

@ -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 {}

View File

@ -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)?

View File

@ -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')

View File

@ -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)

View File

@ -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 {}
//

View File

@ -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 {

View File

@ -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) {

View File

@ -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 {}