Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor, update, remove-repo #2

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor 2.3
Alessandro-Salerno committed Nov 13, 2024
commit 6a9a9ba2446c2d6bab524f03ba061a92ac5f0dcd
47 changes: 38 additions & 9 deletions src/common/cli/directives/commands/update.c
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ int cli_cmd_update(cli_info_t info) {
char *pkg_path = NULL;
char *tmp_archive_path = NULL;
char *artifact_path = NULL;
char *pkg_rcp_path = NULL;
recipe_t recipe_artifact = {0};

if (NULL == pkg_name) {
@@ -44,11 +45,6 @@ int cli_cmd_update(cli_info_t info) {
return ret;
}

// TODO: Remove this once it's done
if (!cli_in_bool("WARNING: This is a testing command, proceed?")) {
return EXIT_SUCCESS;
}

cli_out_progress("Initializing host file system");

if (!os_fs_tm_init()) {
@@ -69,10 +65,13 @@ int cli_cmd_update(cli_info_t info) {
goto cleanup;
}

// TODO: Check repository
// TODO: Basically everything from here should use common functions
// by "common functions' I mean functions shared by install, update
// and similar commands"
if (NULL != recipe_artifact.pkg_info.from_repoistory &&
!util_pkg_load_recipe(&recipe_artifact,
recipe_artifact.pkg_info.from_repoistory,
pkg_name,
LOG_ON)) {
goto cleanup;
}

if (NULL == recipe_artifact.pkg_info.url ||
NULL == recipe_artifact.package_format) {
@@ -105,6 +104,10 @@ int cli_cmd_update(cli_info_t info) {
goto cleanup;
}

if (!util_pkg_create_directory_from_path(pkg_path, LOG_ON, INPUT_OFF)) {
goto cleanup;
}

cli_out_progress(
"Extracting archive '%s' to '%s'", tmp_archive_path, pkg_path);

@@ -115,6 +118,31 @@ int cli_cmd_update(cli_info_t info) {
goto cleanup;
}

os_fs_path_dyconcat(&pkg_rcp_path, 2, pkg_path, "recipe.tarman");
cli_out_progress("Creating recipe artifact in '%s'", pkg_rcp_path);
pkg_dump_rcp(pkg_rcp_path, recipe_artifact);

if (NULL != recipe_artifact.pkg_info.executable_path) {
char *exec_full_path = NULL;
os_fs_path_dyconcat(
&exec_full_path, 2, pkg_path, recipe_artifact.pkg_info.executable_path);

if (recipe_artifact.add_to_path) {
util_pkg_add_to_path(exec_full_path, LOG_ON);
}

if (recipe_artifact.add_to_desktop) {
util_pkg_add_to_desktop(pkg_path,
recipe_artifact.pkg_info.application_name,
exec_full_path,
recipe_artifact.pkg_info.working_directory,
recipe_artifact.pkg_info.icon_path,
LOG_ON);
}

mem_safe_free(exec_full_path);
}

cli_out_progress("Removing cache '%s'", tmp_archive_path);

if (TM_FS_FILEOP_STATUS_OK != os_fs_file_rm(tmp_archive_path)) {
@@ -128,6 +156,7 @@ int cli_cmd_update(cli_info_t info) {
mem_safe_free(pkg_path);
mem_safe_free(tmp_archive_path);
mem_safe_free(artifact_path);
mem_safe_free(pkg_rcp_path);
pkg_free_rcp(recipe_artifact);
return ret;
}