From 0086b359da3e1ab70aefbbeba3eccb96031eea4d Mon Sep 17 00:00:00 2001 From: Laurent Cheylus Date: Thu, 19 Sep 2024 15:53:11 +0200 Subject: [PATCH] analyzer: merge creation of vtmp directory for check-updates/up commands Merge creation of 'v-analyzer' vtmp directory in src/utils.v, function download_install_vsh => called by 'check-updates' and 'up' commands. Signed-off-by: Laurent Cheylus --- src/check-updates.v | 5 ----- src/up.v | 7 +------ src/utils.v | 5 +++++ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/check-updates.v b/src/check-updates.v index 920d8a92..43acbe16 100644 --- a/src/check-updates.v +++ b/src/check-updates.v @@ -1,13 +1,8 @@ module main import cli -import os fn check_updates_cmd(_ cli.Command) ! { - if !os.exists(analyzer_dir) { - os.mkdir(analyzer_dir)! - } - download_install_vsh()! call_install_vsh('check-updates')! } diff --git a/src/up.v b/src/up.v index fbeaf0b9..87662ea7 100644 --- a/src/up.v +++ b/src/up.v @@ -4,15 +4,10 @@ import cli import term import os -pub const analyzer_dir = os.join_path(os.vtmp_dir(), 'v-analyzer') pub const analyzer_install_script_download_path = 'https://raw.githubusercontent.com/vlang/v-analyzer/main/install.vsh' -pub const analyzer_install_script_path = os.join_path(analyzer_dir, 'install.vsh') +pub const analyzer_install_script_path = os.join_path(os.vtmp_dir(), 'v-analyzer', 'install.vsh') fn up_cmd(cmd cli.Command) ! { - if !os.exists(analyzer_dir) { - os.mkdir(analyzer_dir)! - } - download_install_vsh()! is_nightly := cmd.flags.get_bool('nightly') or { false } diff --git a/src/utils.v b/src/utils.v index f684e5d9..8e03a437 100644 --- a/src/utils.v +++ b/src/utils.v @@ -21,6 +21,11 @@ pub fn successln(msg string) { } pub fn download_install_vsh() ! { + download_dir := os.join_path(os.vtmp_dir(), 'v-analyzer') + if !os.exists(download_dir) { + os.mkdir(download_dir) or { return error('Failed to create tmp dir: ${err}') } + } + http.download_file(analyzer_install_script_download_path, analyzer_install_script_path) or { return error('Failed to download script: ${err}') }