Skip to content

Commit

Permalink
Close #21
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexDev23 committed May 16, 2023
1 parent 8c2ffec commit 4d4106b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/libjapml/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ japml_list_t* japml_json_to_pkg_file(json_object *obj)
json_object* url_obj = json_object_object_get(item, "url");
json_object* file_loc_obj = json_object_object_get(item, "file name");

pkg_file->url = (char*)json_object_get_string(url_obj);
pkg_file->rel_file_loc = (char*)json_object_get_string(file_loc_obj);
pkg_file->url = japml_json_obj_to_string(url_obj);
pkg_file->rel_file_loc = japml_json_obj_to_string(file_loc_obj);

japml_list_add(&files, pkg_file);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/libjapml/package.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ int japml_package_add_to_list_no_rep(japml_list_t** list, japml_package_t* packa
void japml_package_free_f(void* ptr)
{
japml_package_file_t* file = (japml_package_file_t*)ptr;
if (file == NULL)
{
return;
}

free(file->url);
free(file->rel_file_loc);
free(file);
Expand Down
2 changes: 1 addition & 1 deletion lib/libjapml/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ japml_list_t* japml_get_param_list(int count, int argc, char** argv)
japml_list_t* list = NULL;
while (argv[count + 1] != NULL && !japml_input_is_param(argv[count + 1]))
{
char* param = malloc(sizeof(char) * (strlen(argv[count + 1]) + 1));
char* param = malloc(strlen(argv[count + 1]) + 1);
strcpy(param, argv[count + 1]);
japml_list_add(&list, param);
count++;
Expand Down
11 changes: 7 additions & 4 deletions lib/libjapml/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

int japml_run_single_instruction(char* instruction, char* dir)
{
char* cmd = japml_str_replace(instruction, JAPML_PACKAGE_DIR_VAR, dir);
char* cmd1 = japml_str_replace(instruction, JAPML_PACKAGE_DIR_VAR "/", dir);
char* cmd2 = japml_str_replace(cmd1, JAPML_PACKAGE_DIR_VAR, dir);

char* surpressed_cmd = malloc(strlen(cmd) + strlen(" 1> 2> ")
free(cmd1);

char* surpressed_cmd = malloc(strlen(cmd2) + strlen(" 1>> 2>> ")
+ strlen(JAPML_SYSTEM_OUT_STDIO) + strlen(JAPML_SYSTEM_OUT_ERR) + 1);

sprintf(surpressed_cmd, "%s 1> " JAPML_SYSTEM_OUT_STDIO " 2> " JAPML_SYSTEM_OUT_ERR, cmd);
sprintf(surpressed_cmd, "%s 1>> " JAPML_SYSTEM_OUT_STDIO " 2>> " JAPML_SYSTEM_OUT_ERR, cmd2);

free(cmd);
free(cmd2);

if (system(surpressed_cmd) == -1)
{
Expand Down
6 changes: 2 additions & 4 deletions src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ int update_packages(japml_handle_t* handle, japml_list_t* targets, bool systemwi

if (systemwide)
{
if (targets != NULL ) { japml_list_free(targets); }

// We ignore the passed targets since we are doing a system wide update
targets = japml_db_local_get_all_packages_name(handle);
}
Expand All @@ -23,17 +25,13 @@ int update_packages(japml_handle_t* handle, japml_list_t* targets, bool systemwi

if (remove_packages(handle, targets, true))
{
japml_list_free_data(targets);
return -1;
}

if (install_packages(handle, targets))
{
japml_list_free_data(targets);
return -1;
}

japml_list_free_data(targets);

return 0;
}

0 comments on commit 4d4106b

Please sign in to comment.