update: migrating calls to the new libmp changes

This commit is contained in:
ngn 2024-08-01 00:45:03 +03:00
parent 44e68414b9
commit 33e59c6644
10 changed files with 145 additions and 100 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-19 22:56+0300\n"
"POT-Creation-Date: 2024-07-31 23:21+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -121,10 +121,10 @@ msgstr ""
msgid "Here is a list of available global options:"
msgstr ""
#: src/main.c:124 src/main.c:125 src/cmd/info.c:19 src/cmd/info.c:20
#: src/cmd/info.c:21 src/cmd/install.c:25 src/cmd/install.c:26
#: src/main.c:124 src/main.c:125 src/cmd/info.c:42 src/cmd/info.c:43
#: src/cmd/info.c:44 src/cmd/install.c:25 src/cmd/install.c:26
#: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:20 src/cmd/remove.c:21
#: src/cmd/update.c:25
#: src/cmd/update.c:29
#, c-format
msgid " "
msgstr ""
@ -148,74 +148,74 @@ msgstr "Sunucuyu başlatmak başarısız oldu: %s"
msgid "Failed to open the editor: %s"
msgstr "Sunucuyu başlatmak başarısız oldu: %s"
#: src/cmd/info.c:18 src/cmd/list.c:12
#: src/cmd/info.c:18 src/cmd/info.c:28 src/cmd/install.c:59 src/cmd/remove.c:45
msgid "Package "
msgstr ""
#: src/cmd/info.c:41 src/cmd/list.c:12
msgid "Listing options for the list command:"
msgstr ""
#: src/cmd/info.c:41
#: src/cmd/info.c:65
msgid "Please specify only a single package name"
msgstr ""
#: src/cmd/info.c:47
#: src/cmd/info.c:71
#, fuzzy
msgid "Please specify a single package"
msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
#: src/cmd/info.c:53 src/cmd/info.c:59 src/cmd/install.c:59 src/cmd/remove.c:45
msgid "Package "
msgstr ""
#: src/cmd/info.c:64
#: src/cmd/info.c:86
#, fuzzy
msgid "Failed to get the changes file for "
msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
#: src/cmd/info.c:70
#: src/cmd/info.c:92
#, fuzzy
msgid "Failed to access the changes file, is the package installed?"
msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
#: src/cmd/info.c:77
#: src/cmd/info.c:99
#, fuzzy
msgid "Failed to get the depends list for "
msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
#: src/cmd/info.c:104
#: src/cmd/info.c:126
#, c-format
msgid "Name "
msgstr ""
#: src/cmd/info.c:105
#: src/cmd/info.c:127
#, c-format
msgid "Version "
msgstr ""
#: src/cmd/info.c:106
#: src/cmd/info.c:128
#, c-format
msgid "Desc "
msgstr ""
#: src/cmd/info.c:107
#: src/cmd/info.c:129
#, c-format
msgid "Size "
msgstr ""
#: src/cmd/info.c:110
#: src/cmd/info.c:132
#, c-format
msgid "Depends "
msgstr ""
#: src/cmd/info.c:113
#: src/cmd/info.c:135
#, c-format
msgid "Changes "
msgstr ""
#: src/cmd/info.c:117 src/cmd/info.c:118
#: src/cmd/info.c:139 src/cmd/info.c:140
#, c-format
msgid "Installed "
msgstr ""
#: src/cmd/info.c:120 src/cmd/info.c:121
#: src/cmd/info.c:142 src/cmd/info.c:143
#, c-format
msgid "Up-to-date "
msgstr ""
@ -224,7 +224,7 @@ msgstr ""
msgid "Listing options for the install command:"
msgstr ""
#: src/cmd/install.c:31 src/cmd/update.c:30
#: src/cmd/install.c:31 src/cmd/update.c:34
msgid "There are no avaliable pools, have you synced yet?"
msgstr ""
@ -243,7 +243,7 @@ msgid "Nothing to do (no packages to install)"
msgstr ""
#: src/cmd/install.c:80 src/cmd/install.c:82 src/cmd/remove.c:67
#: src/cmd/remove.c:69 src/cmd/update.c:50 src/cmd/update.c:52
#: src/cmd/remove.c:69 src/cmd/update.c:55 src/cmd/update.c:57
msgid "Following "
msgstr ""
@ -251,34 +251,39 @@ msgstr ""
msgid "Total of "
msgstr ""
#: src/cmd/install.c:89 src/cmd/remove.c:77 src/cmd/update.c:58
#: src/cmd/install.c:91 src/cmd/update.c:64
#, c-format
msgid "Root directory is modified, install scripts will be saved in %s"
msgstr ""
#: src/cmd/install.c:93 src/cmd/remove.c:77 src/cmd/update.c:66
msgid "Continue?"
msgstr ""
#: src/cmd/install.c:90 src/cmd/remove.c:78 src/cmd/update.c:59
#: src/cmd/install.c:94 src/cmd/remove.c:78 src/cmd/update.c:67
msgid "Operation cancelled"
msgstr ""
#: src/cmd/install.c:96 src/cmd/install.c:111 src/cmd/remove.c:85
#: src/cmd/update.c:69 src/cmd/update.c:78 src/cmd/update.c:87
#: src/cmd/install.c:100 src/cmd/install.c:115 src/cmd/remove.c:85
#: src/cmd/update.c:77 src/cmd/update.c:86 src/cmd/update.c:95
msgid "("
msgstr ""
#: src/cmd/install.c:102 src/cmd/update.c:74
#: src/cmd/install.c:106 src/cmd/update.c:82
#, fuzzy
msgid "Failed to download "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:117 src/cmd/update.c:92
#: src/cmd/install.c:121 src/cmd/update.c:100
#, fuzzy
msgid "Failed to install "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:123
#: src/cmd/install.c:127
msgid "Installed "
msgstr ""
#: src/cmd/install.c:123
#: src/cmd/install.c:127
msgid "Installed all of the "
msgstr ""
@ -303,7 +308,7 @@ msgstr "Havuzları sekronize etmek başarısız oldu: %s"
msgid "Nothing to do (no packages to remove)"
msgstr ""
#: src/cmd/remove.c:91 src/cmd/update.c:83
#: src/cmd/remove.c:91 src/cmd/update.c:91
#, fuzzy
msgid "Failed to remove "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
@ -340,20 +345,20 @@ msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
msgid "Failed to sync pools: %s"
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/update.c:24
#: src/cmd/update.c:28
msgid "Listing options for the update command:"
msgstr ""
#: src/cmd/update.c:40
#: src/cmd/update.c:45
#, fuzzy, c-format
msgid "Failed to get the package update list: %s"
msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
#: src/cmd/update.c:45
#: src/cmd/update.c:50
msgid "All packages are up-to-date"
msgstr ""
#: src/cmd/update.c:65
#: src/cmd/update.c:73
#, fuzzy
msgid "Failed to update "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"

View File

@ -1,5 +1,6 @@
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/database.h>
#include <libmp/error.h>
#include <libmp/package.h>
#include <stdio.h>
@ -9,6 +10,28 @@
#include "../cmd.h"
#include "../log.h"
lm_pkg_data_t *cmd_info_from_pool(lm_ctx_t *ctx, args_t *args, char *name){
lm_pkg_t *pkg = NULL;
if((pkg = lm_ctx_pool_find(ctx, name, NULL)) == NULL){
if(!args_get_bool(args, "grep") && LM_ERR_PkgNotFound == lm_error())
error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name);
return NULL;
}
return &pkg->data;
}
lm_pkg_data_t *cmd_info_from_database(lm_ctx_t *ctx, lm_entry_t *entry, args_t *args, char *name){
if(!lm_ctx_database_find(ctx, entry, name, NULL)){
if(!args_get_bool(args, "grep") && LM_ERR_DbSqlNotFound == lm_error())
error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name);
return NULL;
}
return entry;
}
bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
args_split(args, "grep");
args_split(args, "changes");
@ -26,7 +49,8 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
lm_ctx_sync(ctx, false, NULL, NULL);
char *name = NULL, *depends = NULL, *changes = NULL;
lm_pkg_t pkg, *pkgp = &pkg;
lm_pkg_data_t *data = NULL;
lm_entry_t ent;
for(size_t i = 0; i < args->count; i++){
if(NULL != args->list[i].name || eq(args->list[i].value, "info"))
@ -48,20 +72,18 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
return false;
}
if(args_get_bool(args, "database") && !lm_ctx_database_find(ctx, &pkg, name, NULL)){
if(!args_get_bool(args, "grep") && LM_ERR_DbSqlNotFound == lm_error())
error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name);
return false;
if(args_get_bool(args, "database")){
if((data = cmd_info_from_database(ctx, &ent, args, name)) == NULL)
return false;
}
else if(!args_get_bool(args, "database") && (pkgp = lm_ctx_pool_find(ctx, name, NULL)) == NULL){
if(!args_get_bool(args, "grep") && LM_ERR_PkgNotFound == lm_error())
error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name);
return false;
else if(!args_get_bool(args, "database")){
if((data = cmd_info_from_pool(ctx, args, name)) == NULL)
return false;
}
if((changes = lm_ctx_database_changes(ctx, pkgp)) == NULL && LM_ERR_DbChangesNotExists != lm_error()){
error(_("Failed to get the changes file for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgp->name, pkgp->version, lm_strerror());
if((changes = lm_ctx_database_changes(ctx, data)) == NULL && LM_ERR_DbChangesNotExists != lm_error()){
error(_("Failed to get the changes file for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), data->name, data->version, lm_strerror());
goto end;
}
@ -73,57 +95,57 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
goto end;
}
if((depends = lm_package_depend_tostr(pkgp, NULL)) == NULL){
error(_("Failed to get the depends list for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgp->name, pkgp->version, lm_strerror());
if((depends = lm_package_data_depend_tostr(data, NULL)) == NULL){
error(_("Failed to get the depends list for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), data->name, data->version, lm_strerror());
goto end;
}
if(args_get_bool(args, "grep")){
printf("NAME:%s\n", pkgp->name);
printf("VERSION:%s\n", pkgp->version);
printf("DESC:%s\n", pkgp->desc);
printf("SIZE:%lu\n", pkgp->size);
printf("NAME:%s\n", data->name);
printf("VERSION:%s\n", data->version);
printf("DESC:%s\n", data->desc);
printf("SIZE:%lu\n", data->size);
if(lm_package_depend_count(pkgp) > 0)
if(lm_package_data_depend_count(data) > 0)
printf("DEPENDS:%s\n", depends);
if(NULL != changes)
printf("CHANGES:%s\n", changes);
if(!args_get_bool(args, "database")){
printf("INSTALLED:%d\n", lm_ctx_database_is_installed(ctx, pkgp, false));
printf("UPTODATE:%d\n", lm_ctx_database_is_installed(ctx, pkgp, true));
printf("INSTALLED:%d\n", lm_ctx_database_is_installed(ctx, data->name, NULL));
printf("UPTODATE:%d\n", lm_ctx_database_is_installed(ctx, data->name, data->version));
}
goto end;
}
char ssize[LONGSTR_MAX+1];
size_to_human(ssize, pkgp->size);
size_to_human(ssize, data->size);
printf(_(FG_BOLD"Name "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->name);
printf(_(FG_BOLD"Version "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->version);
printf(_(FG_BOLD"Desc "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->desc);
printf(_(FG_BOLD"Name "FG_BLUE"=>"FG_RESET" %s\n"), data->name);
printf(_(FG_BOLD"Version "FG_BLUE"=>"FG_RESET" %s\n"), data->version);
printf(_(FG_BOLD"Desc "FG_BLUE"=>"FG_RESET" %s\n"), data->desc);
printf(_(FG_BOLD"Size "FG_BLUE"=>"FG_RESET" %s\n"), ssize);
if(lm_package_depend_count(pkgp) > 0)
if(lm_package_data_depend_count(data) > 0)
printf(_(FG_BOLD"Depends "FG_BLUE"=>"FG_RESET" %s\n"), depends);
if(NULL != changes)
printf(_(FG_BOLD"Changes "FG_BLUE"=>"FG_RESET" %s\n"), changes);
if(!args_get_bool(args, "database")){
printf(lm_ctx_database_is_installed(ctx, pkgp, false) ?
printf(lm_ctx_database_is_installed(ctx, data->name, NULL) ?
_(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") :
_(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n"));
printf(lm_ctx_database_is_installed(ctx, pkgp, true) ?
printf(lm_ctx_database_is_installed(ctx, data->name, data->version) ?
_(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") :
_(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n"));
}
end:
if(args_get_bool(args, "database"))
lm_package_free(pkgp);
lm_entry_free(&ent);
free(changes);
free(depends);

View File

@ -55,8 +55,8 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
goto end;
}
if(lm_ctx_database_is_installed(ctx, pkg, true)){
error(_("Package "FG_BOLD"%s"FG_RESET"_"FG_GREEN"%s"FG_RESET" is already installed"), name, pkg->version);
if(lm_ctx_database_is_installed(ctx, pkg->data.name, pkg->data.version)){
error(_("Package "FG_BOLD"%s"FG_RESET"_"FG_GREEN"%s"FG_RESET" is already installed"), name, pkg->data.version);
goto end;
}
@ -73,7 +73,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
}
while((pkg = lm_ctx_resolve_next(list)) != NULL)
size += pkg->size;
size += pkg->data.size;
size_to_human(ssize, size);
if(list->count == 1)
@ -82,10 +82,14 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
info(_("Following "FG_BOLD"%d"FG_RESET" packages will be "FG_BOLD"INSTALLED:"FG_RESET), list->count);
while((pkg = lm_ctx_resolve_next(list)) != NULL)
package_list(pkg, &save, 0);
package_list(&pkg->data, &save, 0);
printf("\n");
info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be used"), ssize);
if(!can_run_install(ctx))
info(_(FG_BOLD"Root directory is modified, install scripts will be saved in %s"FG_RESET), ctx->data);
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled"));
goto end;
@ -93,13 +97,13 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
// download resolved packages
while((pkg = lm_ctx_resolve_next(list)) != NULL){
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Downloading "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, pkg->name, pkg->version);
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Downloading "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, pkg->data.name, pkg->data.version);
r = lm_ctx_download(ctx, pkg, cmd_download_callback, NULL);
bar_free();
if(!r){
error(_("Failed to download "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkg->name, pkg->version, lm_strerror());
error(_("Failed to download "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkg->data.name, pkg->data.version, lm_strerror());
goto end;
}
}
@ -108,13 +112,13 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
// install resolved packages
while((pkg = lm_ctx_resolve_next(list)) != NULL){
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Installing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, pkg->name, pkg->version);
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Installing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, pkg->data.name, pkg->data.version);
r = lm_ctx_install(ctx, pkg, cmd_install_callback, NULL);
r = lm_ctx_install(ctx, pkg, can_run_install(ctx), cmd_install_callback, NULL);
bar_free();
if(!r){
error(_("Failed to install "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkg->name, pkg->version, lm_strerror());
error(_("Failed to install "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkg->data.name, pkg->data.version, lm_strerror());
goto end;
}
}

View File

@ -16,11 +16,11 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
}
ssize_t count = 0;
lm_pkg_t pkg;
lm_entry_t ent;
while(lm_ctx_database_next(ctx, &pkg))
while(lm_ctx_database_next(ctx, &ent))
count++;
lm_ctx_database_next_free(ctx, &pkg);
lm_ctx_database_next_free(ctx, &ent);
if(count <= 0){
if(!args_get_bool(args, "grep"))
@ -31,21 +31,21 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
if(!args_get_bool(args, "grep"))
info(count > 1 ? _("Listing "FG_BOLD"%d"FG_RESET" packages") : _("Listing "FG_BOLD"%d"FG_RESET" package"), count);
while(lm_ctx_database_next(ctx, &pkg)){
while(lm_ctx_database_next(ctx, &ent)){
if(args_get_bool(args, "grep")){
if(args_get_bool(args, "desc"))
printf("%s:%s:%s\n", pkg.name, pkg.version, pkg.desc);
printf("%s:%s:%s\n", ent.name, ent.version, ent.desc);
else
printf("%s:%s\n", pkg.name, pkg.version);
printf("%s:%s\n", ent.name, ent.version);
continue;
}
if(args_get_bool(args, "desc"))
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s\n", pkg.name, pkg.version, pkg.desc);
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s\n", ent.name, ent.version, ent.desc);
else
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET"\n", pkg.name, pkg.version);
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET"\n", ent.name, ent.version);
}
lm_ctx_database_next_free(ctx, &pkg);
lm_ctx_database_next_free(ctx, &ent);
return true;
}

View File

@ -6,7 +6,7 @@
#include "../cmd.h"
#include "../log.h"
bool cmd_remove_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){
bool cmd_remove_callback(lm_ctx_t *ctx, lm_entry_t *ent, char *file, size_t current, size_t total, void *data){
bar(current, total);
return true;
}
@ -25,7 +25,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
ssize_t count = 0, size = 0, current = 0, save = 0;
bool ret = false, r = false;
char ssize[LONGSTR_MAX+3];
lm_pkg_t *pkgs = NULL;
lm_entry_t *pkgs = NULL;
char *name = NULL;
for(int i = 0; i < args->count; i++){
@ -80,7 +80,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
}
for(int i = 0; i < count; i++){
lm_pkg_t *cur = &pkgs[i];
lm_entry_t *cur = &pkgs[i];
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Removing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET), ++current, count, cur->name, cur->version);
@ -102,7 +102,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
end:
if(NULL != pkgs)
for(int i = 0; i < count; i++)
lm_package_free(&pkgs[i]);
lm_entry_free(&pkgs[i]);
bar_free();
return ret;
}

View File

@ -1,12 +1,16 @@
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/error.h>
#include <stdio.h>
#include "../util.h"
#include "../cmd.h"
#include "../log.h"
bool cmd_update_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){
bool cmd_update_remove_callback(lm_ctx_t *ctx, lm_entry_t *ent, char *file, size_t current, size_t total, void *data){
bar(current, total);
return true;
}
bool cmd_update_install_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){
bar(current, total);
return true;
}
@ -31,7 +35,8 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
return false;
}
lm_pkg_t *old = NULL, *new = NULL;
lm_entry_t *old = NULL;
lm_pkg_t *new = NULL;
lm_ctx_update_list_t *list = NULL;
ssize_t current = 0, save = 0;
bool ret = false, r = false;
@ -55,6 +60,9 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
package_list(old, &save, 0);
printf("\n");
if(!can_run_install(ctx))
info(_(FG_BOLD"Root directory is modified, install scripts will be saved in %s"FG_RESET), ctx->data);
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled"));
goto end;
@ -66,17 +74,17 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
goto end;
}
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Downloading "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, new->name, new->version);
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Downloading "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, new->data.name, new->data.version);
r = lm_ctx_download(ctx, new, cmd_update_download_callback, NULL);
bar_free();
if(!r){
error(_("Failed to download "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), new->name, new->version, lm_strerror());
error(_("Failed to download "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), new->data.name, new->data.version, lm_strerror());
goto end;
}
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Removing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), current, list->count, old->name, old->version);
r = lm_ctx_remove(ctx, old, cmd_update_callback, NULL);
r = lm_ctx_remove(ctx, old, cmd_update_remove_callback, NULL);
bar_free();
if(!r){
@ -84,12 +92,12 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
goto end;
}
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Installing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), current, list->count, new->name, new->version);
r = lm_ctx_install(ctx, new, cmd_update_callback, NULL);
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Installing "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), current, list->count, new->data.name, new->data.version);
r = lm_ctx_install(ctx, new, can_run_install(ctx), cmd_update_install_callback, NULL);
bar_free();
if(!r){
error(_("Failed to install "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), new->name, new->version, lm_strerror());
error(_("Failed to install "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), new->data.name, new->data.version, lm_strerror());
goto end;
}
}

View File

@ -11,7 +11,7 @@
#include "intl.h"
#include "log.h"
void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max) {
void package_list(lm_pkg_data_t *pkg, ssize_t *save, ssize_t max) {
ssize_t cur = 0;
if (*save == 0) {
@ -39,7 +39,7 @@ void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max) {
}
end:
printf(FG_BOLD "%s" FG_RESET "_" FG_BOLD FG_GREEN "%s", pkg->name, pkg->version);
printf(FG_BOLD "%s" FG_RESET "_" FG_BOLD FG_GREEN "%s" FG_RESET, pkg->name, pkg->version);
printf(" ");
}

View File

@ -12,7 +12,7 @@
#define FG_MAGENTA "\x1b[35m"
#define FG_RESET "\x1b[0m"
void package_list(lm_pkg_t *pkg, ssize_t *save, ssize_t max);
void package_list(lm_pkg_data_t *pkg, ssize_t *save, ssize_t max);
void info(const char *msg, ...);
void error(const char *msg, ...);
void success(const char *msg, ...);

View File

@ -100,3 +100,7 @@ end:
free(editor);
return;
}
bool can_run_install(lm_ctx_t *ctx) {
return eq(ctx->root, "/");
}

View File

@ -1,4 +1,5 @@
#pragma once
#include <libmp/all.h>
#include <stdbool.h>
#define LONGSTR_MAX 30
@ -8,3 +9,4 @@ bool startswith(char *str, char *sub);
void size_to_human(char *buf, long size);
char *exists_in_path(char *file);
void editor_open(char *file);
bool can_run_install(lm_ctx_t *ctx);