From ba287538039cd8e89529aa1ad3891386d358575d Mon Sep 17 00:00:00 2001 From: Shaw Date: Sat, 24 Feb 2024 18:34:33 -0500 Subject: [PATCH] c-tooling: handle first time orca install The first time a user installs orca.exe and then runs orca update, the current_version file doesn't exist yet, so this commit handles that case by just installing the latest version without attempting to update cli tool, and writing that version to the current_version file. --- src/tool/update.c | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/tool/update.c b/src/tool/update.c index c9329f72..80395455 100644 --- a/src/tool/update.c +++ b/src/tool/update.c @@ -100,31 +100,36 @@ int update(int argc, char** argv) //----------------------------------------------------------------------------- // update cli tool executable //----------------------------------------------------------------------------- - { - oc_str8 current_version_path = oc_path_append(&arena, orca_dir, OC_STR8("current_version")); - oc_file file = oc_file_open(current_version_path, OC_FILE_ACCESS_READ, OC_FILE_OPEN_NONE); - if(oc_file_is_nil(file)) - { - fprintf(stderr, "error: failed to identify current Orca version\n"); - return 1; - } - oc_str8 current_version = {0}; - current_version.len = oc_file_size(file); - current_version.ptr = oc_arena_push(&arena, current_version.len + 1); - oc_file_read(file, current_version.len, current_version.ptr); - if(oc_file_last_error(file) != OC_IO_OK) - { - fprintf(stderr, "error: failed to identify current Orca version\n"); - return 1; - } - oc_file_close(file); + oc_str8 current_version_path = oc_path_append(&arena, orca_dir, OC_STR8("current_version")); + if(oc_sys_exists(current_version_path)) + { + oc_file file = oc_file_open(current_version_path, OC_FILE_ACCESS_READ, OC_FILE_OPEN_NONE); + if(oc_file_is_nil(file)) + { + fprintf(stderr, "error: failed to identify current Orca version\n"); + return 1; + } + oc_str8 current_version = {0}; + current_version.len = oc_file_size(file); + current_version.ptr = oc_arena_push(&arena, current_version.len + 1); + oc_file_read(file, current_version.len, current_version.ptr); + if(oc_file_last_error(file) != OC_IO_OK) + { + fprintf(stderr, "error: failed to identify current Orca version\n"); + return 1; + } + oc_file_close(file); - current_version = oc_str8_trim_space(current_version); - if(oc_str8_cmp(current_version, version) != 0) - { - return replace_yourself_and_update(curl, repo_url_base, orca_dir, current_version, version); - } - } + current_version = oc_str8_trim_space(current_version); + if(oc_str8_cmp(current_version, version) != 0) + { + return replace_yourself_and_update(curl, repo_url_base, orca_dir, current_version, version); + } + } + // NOTE(shaw): if current_version file doesn't exist, then we assume that + // the user has just installed the cli tool for the first time, so proceed + // with downloading the latest version and writing that version to the + // current_version file //----------------------------------------------------------------------------- // download and extract latest version