Skip to content

Commit

Permalink
c-tooling: handle first time orca install
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bitwitch committed Feb 24, 2024
1 parent 89b38d8 commit ba28753
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions src/tool/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba28753

Please sign in to comment.