new: update command
This commit is contained in:
@@ -23,6 +23,11 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
|
||||
error(_("There are no avaliable pools, have you synced yet?"));
|
||||
goto end;
|
||||
}
|
||||
|
||||
lm_ctx_resolve_list_t *list = NULL;
|
||||
bool ret = false, r = false;
|
||||
@@ -31,11 +36,6 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
lm_pkg_t *pkg = NULL;
|
||||
char *name = NULL;
|
||||
|
||||
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
|
||||
error(_("There are no avaliable pools, have you synced yet?"));
|
||||
goto end;
|
||||
}
|
||||
|
||||
for(int i = 0; i < args->count; i++){
|
||||
if(NULL != args->list[i].name)
|
||||
continue;
|
||||
|
@@ -6,30 +6,14 @@
|
||||
#include "../cmd.h"
|
||||
#include "../log.h"
|
||||
|
||||
struct cmd_update_data {
|
||||
ssize_t total;
|
||||
ssize_t current;
|
||||
};
|
||||
bool cmd_update_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){
|
||||
bar(current, total);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmd_update_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_update_state_t state, char *file, size_t current, size_t total, void *data){
|
||||
struct cmd_update_data *cbdata = data;
|
||||
|
||||
switch (state) {
|
||||
case UPDATE_REMOVE:
|
||||
if(current == 0)
|
||||
info(_("(%d/%d) Removing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), cbdata->current, cbdata->total, pkg->name, pkg->version);
|
||||
bool cmd_update_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, size_t current, size_t total, void *data){
|
||||
if(!is_archive)
|
||||
bar(current, total);
|
||||
break;
|
||||
|
||||
case UPDATE_INSTALL:
|
||||
if(current == 0){
|
||||
bar_free();
|
||||
info(_("(%d/%d) Installing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), cbdata->current, cbdata->total, pkg->name, pkg->version);
|
||||
}
|
||||
bar(current, total);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -40,10 +24,14 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
|
||||
error(_("There are no avaliable pools, have you synced yet?"));
|
||||
goto end;
|
||||
}
|
||||
|
||||
lm_pkg_t *old = NULL, *new = NULL;
|
||||
lm_ctx_update_list_t *list = NULL;
|
||||
struct cmd_update_data cbdata;
|
||||
bool ret = false, r = false;
|
||||
lm_pkg_t *pkg = NULL;
|
||||
ssize_t current = 0;
|
||||
|
||||
if((list = lm_ctx_update_list(ctx)) == NULL){
|
||||
@@ -68,15 +56,36 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
goto end;
|
||||
}
|
||||
|
||||
while((pkg = lm_ctx_update_list_next(list)) != NULL){
|
||||
cbdata.current = ++current;
|
||||
cbdata.total = list->count;
|
||||
while((old = lm_ctx_update_list_next(list)) != NULL){
|
||||
if((new = lm_ctx_update(ctx, old)) == NULL){
|
||||
error(_("Failed to update "FG_BOLD"%s"FG_RESET": %s"), old->name, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
r = lm_ctx_update(ctx, pkg, cmd_update_callback, &cbdata);
|
||||
info(_("(%d/%d) Downloading "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), ++current, list->count, new->name, new->version);
|
||||
r = lm_ctx_download(ctx, new, cmd_update_download_callback, NULL);
|
||||
bar_free();
|
||||
|
||||
if(!r){
|
||||
error(_("Failed to update "FG_BOLD"%s"FG_RESET": %s"), pkg->name, lm_strerror());
|
||||
error(_("Failed to download "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET"): %s"), new->name, new->version, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
info(_("(%d/%d) Removing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), current, list->count, old->name, old->version);
|
||||
r = lm_ctx_remove(ctx, old, cmd_update_callback, NULL);
|
||||
bar_free();
|
||||
|
||||
if(!r){
|
||||
error(_("Failed to remove "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET"): %s"), old->name, old->version, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
info(_("(%d/%d) Installing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), current, list->count, new->name, new->version);
|
||||
r = lm_ctx_install(ctx, new, cmd_update_callback, NULL);
|
||||
bar_free();
|
||||
|
||||
if(!r){
|
||||
error(_("Failed to install "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET"): %s"), new->name, new->version, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user