1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: require calling optfn() ? / optfn() or {...} for fn optfn() ? {}

This commit is contained in:
Delyan Angelov
2021-01-26 16:43:10 +02:00
parent 97103f680a
commit e5a84719ca
90 changed files with 1994 additions and 1832 deletions

View File

@ -70,7 +70,8 @@ fn main() {
date := time.unix(commit_date.int())
mut out := os.create('table.html') ?
// Place the new row on top
table = '<tr>
table =
'<tr>
<td>$date.format()</td>
<td><a target=_blank href="https://github.com/vlang/v/commit/$commit">$commit</a></td>
<td>$message</td>
@ -80,15 +81,15 @@ fn main() {
<td>${diff4}ms</td>
</tr>\n' +
table.trim_space()
out.writeln(table)
out.writeln(table) ?
out.close()
// Regenerate index.html
header := os.read_file('header.html') ?
footer := os.read_file('footer.html') ?
mut res := os.create('index.html') ?
res.writeln(header)
res.writeln(table)
res.writeln(footer)
res.writeln(header) ?
res.writeln(table) ?
res.writeln(footer) ?
res.close()
}
exec('git checkout master')
@ -96,9 +97,7 @@ fn main() {
}
fn exec(s string) string {
e := os.exec(s) or {
panic(err)
}
e := os.exec(s) or { panic(err) }
return e.output.trim_right('\r\n')
}
@ -112,7 +111,7 @@ fn measure(cmd string, description string) int {
println(' Building...')
mut runs := []int{}
for r in 0 .. 5 {
println(' Sample ${r+1}/5')
println(' Sample ${r + 1}/5')
sw := time.new_stopwatch({})
exec(cmd)
runs << int(sw.elapsed().milliseconds())

View File

@ -12,21 +12,20 @@ pub fn set_verbose(on bool) {
// but V does not have globals normally.
if on {
os.setenv('VERBOSE', '1', true)
}
else {
} else {
os.unsetenv('VERBOSE')
}
}
pub fn cprintln(message string) {
mut omessage := message
omessage = if term_colors { term.green(omessage) } else { omessage }
omessage = if scripting.term_colors { term.green(omessage) } else { omessage }
println(omessage)
}
pub fn verbose_trace(label string, message string) {
if os.getenv('VERBOSE').len > 0 {
slabel := 'scripting.${label}'
slabel := 'scripting.$label'
cprintln('# ${slabel:-25s} : $message')
}
}
@ -54,9 +53,9 @@ pub fn rmrf(path string) {
verbose_trace(@FN, 'rm -rf $path')
if os.exists(path) {
if os.is_dir(path) {
os.rmdir_all(path)
}else{
os.rm(path)
os.rmdir_all(path) or { panic(err) }
} else {
os.rm(path) or { panic(err) }
}
}
}
@ -97,7 +96,7 @@ pub fn exit_0_status(cmd string) bool {
return false
}
pub fn tool_must_exist (toolcmd string) {
pub fn tool_must_exist(toolcmd string) {
verbose_trace(@FN, toolcmd)
if exit_0_status('type $toolcmd') {
return

View File

@ -210,7 +210,7 @@ pub fn (mut ts TestSession) test() {
// cleanup generated .tmp.c files after successfull tests:
if ts.benchmark.nfail == 0 {
if ts.rm_binaries {
os.rmdir_all(ts.vtmp_dir)
os.rmdir_all(ts.vtmp_dir) or { panic(err) }
}
}
}
@ -241,7 +241,7 @@ fn worker_trunner(mut p sync.PoolProcessor, idx int, thread_id int) voidptr {
generated_binary_fpath := os.join_path(tmpd, generated_binary_fname)
if os.exists(generated_binary_fpath) {
if ts.rm_binaries {
os.rm(generated_binary_fpath)
os.rm(generated_binary_fpath) or { panic(err) }
}
}
mut cmd_options := [ts.vargs]
@ -294,7 +294,7 @@ fn worker_trunner(mut p sync.PoolProcessor, idx int, thread_id int) voidptr {
}
if os.exists(generated_binary_fpath) {
if ts.rm_binaries {
os.rm(generated_binary_fpath)
os.rm(generated_binary_fpath) or { panic(err) }
}
}
return sync.no_result
@ -422,7 +422,7 @@ pub fn header(msg string) {
pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now()
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now')
os.mkdir_all(new_vtmp_dir)
os.mkdir_all(new_vtmp_dir) or { panic(err) }
os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir
}

View File

@ -28,26 +28,26 @@ fn get_vexe_path() string {
fn new_tdir() string {
tdir_ := os.join_path(os.temp_dir(), rand.ulid())
if os.exists(tdir_) {
os.rmdir(tdir_)
os.rmdir(tdir_) or { panic(err) }
}
os.mkdir(tdir_)
os.mkdir(tdir_) or { panic(err) }
C.atexit(cleanup_tdir)
return tdir_
}
fn cleanup_tdir() {
println('... removing tdir: $tdir')
os.rmdir_all(tdir)
os.rmdir_all(tdir) or { panic(err) }
}
fn main() {
println('> vroot: $vroot | vexe: $vexe | tdir: $tdir')
ok_fpath := os.join_path(tdir, 'single_test.v')
os.write_file(ok_fpath, 'fn test_ok(){ assert true }')
os.write_file(ok_fpath, 'fn test_ok(){ assert true }') ?
check_ok('"$vexe" $ok_fpath')
check_ok('"$vexe" test $ok_fpath')
fail_fpath := os.join_path(tdir, 'failing_test.v')
os.write_file(fail_fpath, 'fn test_fail(){ assert 1 == 2 }')
os.write_file(fail_fpath, 'fn test_fail(){ assert 1 == 2 }') ?
check_fail('"$vexe" $fail_fpath')
check_fail('"$vexe" test $fail_fpath')
check_fail('"$vexe" test $tdir')

View File

@ -68,7 +68,6 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string {
sb.write('$b, ')
line_len += b.len + 2
}
}
sb.write(']!\n')
return sb.str()
@ -76,8 +75,8 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string {
fn (context Context) bname_and_bytes(file string) ?(string, []byte) {
fname := os.file_name(file)
fname_escpaed := fname.replace_each(['.', '_', '-', '_'])
byte_name := '$context.prefix$fname_escpaed'.to_lower()
fname_escaped := fname.replace_each(['.', '_', '-', '_'])
byte_name := '$context.prefix$fname_escaped'.to_lower()
fbytes := os.read_bytes(file) or { return error('Error: $err') }
return byte_name, fbytes
}
@ -131,12 +130,12 @@ fn main() {
}
max_bname := context.max_bname_len(file_byte_map.keys())
if context.write_file.len > 0 {
mut out_file := os.create(context.write_file) or { panic(err) }
out_file.write_str(context.header())
mut out_file := os.create(context.write_file) ?
out_file.write_str(context.header()) ?
for bname, fbytes in file_byte_map {
out_file.write_str(context.file2v(bname, fbytes, max_bname))
out_file.write_str(context.file2v(bname, fbytes, max_bname)) ?
}
out_file.write_str(context.footer())
out_file.write_str(context.footer()) ?
} else {
print(context.header())
for bname, fbytes in file_byte_map {

View File

@ -55,9 +55,14 @@ fn main() {
//
tpath := os.join_path(session.vtmp_dir, texe)
if tname in tools_in_subfolders {
os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe))
os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err) }
continue
}
os.mv_by_cp(tpath, os.join_path(tfolder, texe)) or {
if !err.contains('vbuild-tools') {
eprintln(err)
}
continue
}
os.mv_by_cp(tpath, os.join_path(tfolder, texe))
}
}

View File

@ -58,7 +58,7 @@ fn (c &Create) write_vmod(new bool) {
cerror(err)
exit(1)
}
vmod.write_str(vmod_content(c.name, c.description))
vmod.write_str(vmod_content(c.name, c.description)) or { panic(err) }
vmod.close()
}
@ -67,12 +67,12 @@ fn (c &Create) write_main(new bool) {
return
}
main_path := if new { '$c.name/${c.name}.v' } else { '${c.name}.v' }
mut main := os.create(main_path) or {
mut mainfile := os.create(main_path) or {
cerror(err)
exit(2)
}
main.write_str(main_content())
main.close()
mainfile.write_str(main_content()) or { panic(err) }
mainfile.close()
}
fn (c &Create) create_git_repo(dir string) {
@ -87,7 +87,7 @@ fn (c &Create) create_git_repo(dir string) {
// We don't really need a .gitignore, it's just a nice-to-have
return
}
fl.write_str(gen_gitignore(c.name))
fl.write_str(gen_gitignore(c.name)) or { panic(err) }
fl.close()
}
}
@ -110,9 +110,7 @@ fn create() {
}
c.description = os.input('Input your project description: ')
println('Initialising ...')
os.mkdir(c.name) or {
panic(err)
}
os.mkdir(c.name) or { panic(err) }
c.write_vmod(true)
c.write_main(true)
c.create_git_repo(c.name)

View File

@ -126,7 +126,7 @@ fn (vd VDoc) render_search_index(out Output) {
js_search_index.writeln('];')
js_search_data.writeln('];')
out_file_path := os.join_path(out.path, 'search_index.js')
os.write_file(out_file_path, js_search_index.str() + js_search_data.str())
os.write_file(out_file_path, js_search_index.str() + js_search_data.str()) or { panic(err) }
}
fn (mut vd VDoc) render_static_html(out Output) {
@ -162,7 +162,7 @@ fn (vd VDoc) get_resource(name string, out Output) string {
output_path := os.join_path(out.path, name)
if !os.exists(output_path) {
println('Generating $out.typ in "$output_path"')
os.write_file(output_path, res)
os.write_file(output_path, res) or { panic(err) }
}
return name
}

View File

@ -162,7 +162,7 @@ fn (vd VDoc) work_processor(mut work sync.Channel, mut wg sync.WaitGroup) {
file_name, content := vd.render_doc(pdoc.d, pdoc.out)
output_path := os.join_path(pdoc.out.path, file_name)
println('Generating $pdoc.out.typ in "$output_path"')
os.write_file(output_path, content)
os.write_file(output_path, content) or { panic(err) }
}
wg.done()
}
@ -358,7 +358,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
os.mkdir(out.path) or { panic(err) }
} else {
for fname in css_js_assets {
os.rm(os.join_path(out.path, fname))
os.rm(os.join_path(out.path, fname)) or { panic(err) }
}
}
}
@ -376,7 +376,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
for favicon in favicons {
favicon_path := os.join_path(favicons_path, favicon)
destination_path := os.join_path(out.path, favicon)
os.cp(favicon_path, destination_path)
os.cp(favicon_path, destination_path) or { panic(err) }
}
}
}

View File

@ -176,7 +176,7 @@ fn (foptions &FormatOptions) format_file(file string) {
file_name := os.file_name(file)
ulid := rand.ulid()
vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name')
os.write_file(vfmt_output_path, formatted_content)
os.write_file(vfmt_output_path, formatted_content) or { panic(err) }
if foptions.is_verbose {
eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .')
}
@ -258,7 +258,8 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
}
fn (f FormatOptions) str() string {
return 'FormatOptions{ is_l: $f.is_l, is_w: $f.is_w, is_diff: $f.is_diff, is_verbose: $f.is_verbose,' +
return
'FormatOptions{ is_l: $f.is_l, is_w: $f.is_w, is_diff: $f.is_diff, is_verbose: $f.is_verbose,' +
' is_all: $f.is_all, is_worker: $f.is_worker, is_debug: $f.is_debug, is_noerror: $f.is_noerror,' +
' is_verify: $f.is_verify" }'
}

View File

@ -19,15 +19,15 @@ const (
supported_vcs_folders = ['.git', '.hg']
supported_vcs_update_cmds = {
'git': 'git pull'
'hg': 'hg pull --update'
'hg': 'hg pull --update'
}
supported_vcs_install_cmds = {
'git': 'git clone --depth=1'
'hg': 'hg clone'
'hg': 'hg clone'
}
supported_vcs_outdated_steps = {
'git': ['git fetch', 'git rev-parse @', 'git rev-parse @{u}']
'hg': ['hg incoming']
'hg': ['hg incoming']
}
)
@ -71,9 +71,7 @@ fn main() {
'install' {
if module_names.len == 0 && os.exists('./v.mod') {
println('Detected v.mod file inside the project directory. Using it...')
manifest := vmod.from_file('./v.mod') or {
panic(err)
}
manifest := vmod.from_file('./v.mod') or { panic(err) }
module_names = manifest.dependencies
}
vpm_install(module_names)
@ -227,15 +225,11 @@ fn vpm_update(m []string) {
}
mut errors := 0
for name in module_names {
final_module_path := valid_final_path_of_existing_module(name) or {
continue
}
final_module_path := valid_final_path_of_existing_module(name) or { continue }
os.chdir(final_module_path)
println('Updating module "$name"...')
verbose_println(' work folder: $final_module_path')
vcs := vcs_used_in_dir(final_module_path) or {
continue
}
vcs := vcs_used_in_dir(final_module_path) or { continue }
vcs_cmd := supported_vcs_update_cmds[vcs[0]]
verbose_println(' command: $vcs_cmd')
vcs_res := os.exec('$vcs_cmd') or {
@ -265,13 +259,9 @@ fn get_outdated() ?[]string {
module_names := get_installed_modules()
mut outdated := []string{}
for name in module_names {
final_module_path := valid_final_path_of_existing_module(name) or {
continue
}
final_module_path := valid_final_path_of_existing_module(name) or { continue }
os.chdir(final_module_path)
vcs := vcs_used_in_dir(final_module_path) or {
continue
}
vcs := vcs_used_in_dir(final_module_path) or { continue }
vcs_cmd_steps := supported_vcs_outdated_steps[vcs[0]]
mut outputs := []string{}
for step in vcs_cmd_steps {
@ -296,9 +286,7 @@ fn get_outdated() ?[]string {
}
fn vpm_upgrade() {
outdated := get_outdated() or {
exit(1)
}
outdated := get_outdated() or { exit(1) }
if outdated.len > 0 {
vpm_update(outdated)
} else {
@ -307,9 +295,7 @@ fn vpm_upgrade() {
}
fn vpm_outdated() {
outdated := get_outdated() or {
exit(1)
}
outdated := get_outdated() or { exit(1) }
if outdated.len > 0 {
println('Outdated modules:')
for m in outdated {
@ -342,18 +328,16 @@ fn vpm_remove(module_names []string) {
exit(2)
}
for name in module_names {
final_module_path := valid_final_path_of_existing_module(name) or {
continue
}
final_module_path := valid_final_path_of_existing_module(name) or { continue }
println('Removing module "$name"...')
verbose_println('removing folder $final_module_path')
os.rmdir_all(final_module_path)
os.rmdir_all(final_module_path) or { panic(err) }
// delete author directory if it is empty
author := name.split('.')[0]
author_dir := os.real_path(os.join_path(settings.vmodules_path, author))
if os.is_dir_empty(author_dir) {
verbose_println('removing author folder $author_dir')
os.rmdir(author_dir)
os.rmdir(author_dir) or { panic(err) }
}
}
}
@ -380,9 +364,7 @@ fn valid_final_path_of_existing_module(name string) ?string {
fn ensure_vmodules_dir_exist() {
if !os.is_dir(settings.vmodules_path) {
println('Creating $settings.vmodules_path/ ...')
os.mkdir(settings.vmodules_path) or {
panic(err)
}
os.mkdir(settings.vmodules_path) or { panic(err) }
}
}
@ -405,9 +387,7 @@ fn vcs_used_in_dir(dir string) ?[]string {
}
fn get_installed_modules() []string {
dirs := os.ls(settings.vmodules_path) or {
return []
}
dirs := os.ls(settings.vmodules_path) or { return [] }
mut modules := []string{}
for dir in dirs {
adir := os.join_path(settings.vmodules_path, dir)
@ -420,13 +400,9 @@ fn get_installed_modules() []string {
continue
}
author := dir
mods := os.ls(adir) or {
continue
}
mods := os.ls(adir) or { continue }
for m in mods {
vcs_used_in_dir(os.join_path(adir, m)) or {
continue
}
vcs_used_in_dir(os.join_path(adir, m)) or { continue }
modules << '${author}.$m'
}
}
@ -435,9 +411,7 @@ fn get_installed_modules() []string {
fn get_all_modules() []string {
url := get_working_server_url()
r := http.get(url) or {
panic(err)
}
r := http.get(url) or { panic(err) }
if r.status_code != 200 {
println('Failed to search vpm.vlang.io. Status code: $r.status_code')
exit(1)
@ -476,9 +450,7 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
if !os.exists(vmod_path) {
return
}
data := os.read_file(vmod_path) or {
return
}
data := os.read_file(vmod_path) or { return }
vmod := parse_vmod(data)
mut deps := []string{}
// filter out dependencies that were already specified by the user
@ -497,14 +469,12 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
fn parse_vmod(data string) Vmod {
keys := ['name', 'version', 'deps']
mut m := {
'name': ''
'name': ''
'version': ''
'deps': ''
'deps': ''
}
for key in keys {
mut key_index := data.index('$key:') or {
continue
}
mut key_index := data.index('$key:') or { continue }
key_index += key.len + 1
m[key] = data[key_index..data.index_after('\n', key_index)].trim_space().replace("'",
'').replace('[', '').replace(']', '')
@ -519,7 +489,11 @@ fn parse_vmod(data string) Vmod {
}
fn get_working_server_url() string {
server_urls := if settings.server_urls.len > 0 { settings.server_urls } else { default_vpm_server_urls }
server_urls := if settings.server_urls.len > 0 {
settings.server_urls
} else {
default_vpm_server_urls
}
for url in server_urls {
verbose_println('Trying server url: $url')
http.head(url) or {
@ -572,13 +546,11 @@ fn get_module_meta_info(name string) ?Mod {
continue
}
if r.status_code == 404 || r.text.contains('404') {
errors <<
'Skipping module "$name", since $server_url reported that "$name" does not exist.'
errors << 'Skipping module "$name", since $server_url reported that "$name" does not exist.'
continue
}
if r.status_code != 200 {
errors <<
'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
errors << 'Skipping module "$name", since $server_url responded with $r.status_code http status code. Please try again later.'
continue
}
s := r.text

View File

@ -11,10 +11,10 @@ import v.util
struct Repl {
mut:
readline readline.Readline
indent int // indentation level
in_func bool // are we inside a new custom user function
line string // the current line entered by the user
readline readline.Readline
indent int // indentation level
in_func bool // are we inside a new custom user function
line string // the current line entered by the user
//
modules []string // all the import modules
includes []string // all the #include statements
@ -109,21 +109,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
if !is_stdin_a_pipe {
println('')
}
os.rm(file)
os.rm(temp_file)
$if windows {
os.rm(file[..file.len - 2] + '.exe')
os.rm(temp_file[..temp_file.len - 2] + '.exe')
$if msvc {
os.rm(file[..file.len - 2] + '.ilk')
os.rm(file[..file.len - 2] + '.pdb')
os.rm(temp_file[..temp_file.len - 2] + '.ilk')
os.rm(temp_file[..temp_file.len - 2] + '.pdb')
}
} $else {
os.rm(file[..file.len - 2])
os.rm(temp_file[..temp_file.len - 2])
}
cleanup_files([file, temp_file])
}
mut r := new_repl()
vexe := os.getenv('VEXE')
@ -198,7 +184,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
}
if r.line.starts_with('print') {
source_code := r.current_source_code(false) + '\n$r.line\n'
os.write_file(file, source_code)
os.write_file(file, source_code) or { panic(err) }
s := os.exec('"$vexe" -repl run "$file"') or {
rerror(err)
return
@ -208,7 +194,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
mut temp_line := r.line
mut temp_flag := false
func_call := r.function_call(r.line)
filter_line := r.line.replace(r.line.find_between("\'", "\'"), '').replace(r.line.find_between('"',
filter_line := r.line.replace(r.line.find_between("'", "'"), '').replace(r.line.find_between('"',
'"'), '')
possible_statement_patterns := [
'=',
@ -268,7 +254,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
}
temp_source_code = r.current_source_code(true) + '\n$temp_line\n'
}
os.write_file(temp_file, temp_source_code)
os.write_file(temp_file, temp_source_code) or { panic(err) }
s := os.exec('"$vexe" -repl run "$temp_file"') or {
rerror(err)
return
@ -355,3 +341,18 @@ fn (mut r Repl) get_one_line(prompt string) ?string {
rline := r.readline.read_line(prompt) or { return none }
return rline
}
fn cleanup_files(files []string) {
for file in files {
os.rm(file) or { }
$if windows {
os.rm(file[..file.len - 2] + '.exe') or { }
$if msvc {
os.rm(file[..file.len - 2] + '.ilk') or { }
os.rm(file[..file.len - 2] + '.pdb') or { }
}
} $else {
os.rm(file[..file.len - 2]) or { }
}
}
}

View File

@ -4,6 +4,7 @@ import v.pref
$if windows {
$if tinyc {
#flag -lAdvapi32
#flag -lUser32
}
}
@ -19,20 +20,16 @@ fn main() {
fn setup_symlink(vexe string) {
link_dir := '/usr/local/bin'
if !os.exists(link_dir) {
os.mkdir_all(link_dir)
os.mkdir_all(link_dir) or { panic(err) }
}
mut link_path := link_dir + '/v'
mut ret := os.exec('ln -sf $vexe $link_path') or {
panic(err)
}
mut ret := os.exec('ln -sf $vexe $link_path') or { panic(err) }
if ret.exit_code == 0 {
println('Symlink "$link_path" has been created')
} else if os.system("uname -o | grep -q \'[A/a]ndroid\'") == 0 {
} else if os.system("uname -o | grep -q '[A/a]ndroid'") == 0 {
println('Failed to create symlink "$link_path". Trying again with Termux path for Android.')
link_path = '/data/data/com.termux/files/usr/bin/v'
ret = os.exec('ln -sf $vexe $link_path') or {
panic(err)
}
ret = os.exec('ln -sf $vexe $link_path') or { panic(err) }
if ret.exit_code == 0 {
println('Symlink "$link_path" has been created')
} else {
@ -52,9 +49,9 @@ fn setup_symlink_windows(vexe string) {
vsymlinkdir := os.join_path(vdir, '.bin')
mut vsymlink := os.join_path(vsymlinkdir, 'v.exe')
if !os.exists(vsymlinkdir) {
os.mkdir_all(vsymlinkdir) // will panic if fails
os.mkdir_all(vsymlinkdir) or { panic(err) } // will panic if fails
} else {
os.rm(vsymlink)
os.rm(vsymlink) or { panic(err) }
}
// First, try to create a native symlink at .\.bin\v.exe
os.symlink(vsymlink, vexe) or {
@ -64,9 +61,9 @@ fn setup_symlink_windows(vexe string) {
eprintln('Creating a batch file instead...')
vsymlink = os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlink) {
os.rm(vsymlink)
os.rm(vsymlink) or { panic(err) }
}
os.write_file(vsymlink, '@echo off\n$vexe %*')
os.write_file(vsymlink, '@echo off\n$vexe %*') or { panic(err) }
eprintln('$vsymlink file written.')
}
if !os.exists(vsymlink) {
@ -83,9 +80,7 @@ fn setup_symlink_windows(vexe string) {
// C.RegCloseKey(reg_sys_env_handle)
// }
// if the above succeeded, and we cannot get the value, it may simply be empty
sys_env_path := get_reg_value(reg_sys_env_handle, 'Path') or {
''
}
sys_env_path := get_reg_value(reg_sys_env_handle, 'Path') or { '' }
current_sys_paths := sys_env_path.split(os.path_delimiter).map(it.trim('/$os.path_separator'))
mut new_paths := [vsymlinkdir]
for p in current_sys_paths {
@ -171,8 +166,7 @@ fn set_reg_value(reg_key voidptr, key string, value string) ?bool {
// letting them know that the system environment has changed and should be reloaded
fn send_setting_change_msg(message_data string) ?bool {
$if windows {
if C.SendMessageTimeout(os.hwnd_broadcast, os.wm_settingchange, 0, message_data.to_wide(), os.smto_abortifhung, 5000, 0) ==
0 {
if C.SendMessageTimeout(os.hwnd_broadcast, os.wm_settingchange, 0, message_data.to_wide(), os.smto_abortifhung, 5000, 0) == 0 {
return error('Could not broadcast WM_SETTINGCHANGE')
}
return true

View File

@ -108,9 +108,9 @@ fn (app App) show_current_v_version() {
fn (app App) backup(file string) {
backup_file := '${file}_old.exe'
if os.exists(backup_file) {
os.rm(backup_file)
os.rm(backup_file) or { panic(err) }
}
os.mv(file, backup_file)
os.mv(file, backup_file) or { panic(err) }
}
fn (app App) git_command(command string) {

View File

@ -7,7 +7,7 @@ fn main() {
mut cm := vcache.new_cache_manager([])
cpath := cm.basepath
if os.exists(cpath) && os.is_dir(cpath) {
os.rmdir_all(cpath)
os.rmdir_all(cpath) or { }
}
println('V cache folder $cpath was wiped.')
}