new: remove and update operation

This commit is contained in:
ngn 2024-07-17 22:58:13 +03:00
parent 91f513132b
commit ba0583fdf4
7 changed files with 346 additions and 71 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-16 20:30+0300\n"
"POT-Creation-Date: 2024-07-17 22:55+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"
@ -47,28 +47,28 @@ msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
msgid "URL not specified for the pool: %s"
msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s"
#: src/log.c:59
#: src/log.c:58
msgid "y"
msgstr ""
#: src/log.c:59
#: src/log.c:58
msgid "Y"
msgstr ""
#: src/log.c:60
#: src/log.c:59
msgid "n"
msgstr ""
#: src/log.c:60
#: src/log.c:59
msgid "N"
msgstr ""
#: src/log.c:63
#: src/log.c:62
#, c-format
msgid "%s [y/N] "
msgstr ""
#: src/log.c:83
#: src/log.c:82
msgid "Please answer with y/n"
msgstr ""
@ -121,69 +121,100 @@ msgstr ""
msgid "Here is a list of available global options:"
msgstr ""
#: src/main.c:120 src/main.c:121 src/cmd/list.c:13 src/cmd/list.c:14
#: src/main.c:121 src/main.c:122 src/cmd/install.c:22 src/cmd/install.c:23
#: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:17 src/cmd/remove.c:18
#: src/cmd/update.c:39
#, c-format
msgid " "
msgstr ""
#: src/main.c:123
#: src/main.c:124
msgid ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
msgstr ""
#: src/cmd/install.c:30
msgid "There are no avaliable pools"
#: src/cmd/install.c:21
msgid "Listing options for the install command:"
msgstr ""
#: src/cmd/install.c:43
#: src/cmd/install.c:35
msgid "There are no avaliable pools, have you synced yet?"
msgstr ""
#: src/cmd/install.c:48 src/cmd/remove.c:44
#, fuzzy
msgid "Failed to find "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:49
#: src/cmd/install.c:56 src/cmd/remove.c:42
msgid "Package "
msgstr ""
#: src/cmd/install.c:56
#: src/cmd/install.c:62
#, fuzzy
msgid "Failed to resolve "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:62
msgid "Please specify at least one package to install"
#: src/cmd/install.c:68
msgid "Nothing to do (no packages to install)"
msgstr ""
#: src/cmd/install.c:70
msgid "Following packages will be "
#: src/cmd/install.c:77 src/cmd/remove.c:64 src/cmd/update.c:60
#, c-format
msgid "Following %d package will be "
msgstr ""
#: src/cmd/install.c:79 src/cmd/remove.c:66 src/cmd/update.c:62
#, c-format
msgid "Following %d packages will be "
msgstr ""
#. list all the packages
#: src/cmd/install.c:74
#: src/cmd/install.c:83 src/cmd/remove.c:70
msgid "Total of "
msgstr ""
#: src/cmd/install.c:82
#. list all the packages
#: src/cmd/install.c:84 src/cmd/remove.c:71 src/cmd/update.c:66
msgid "Continue?"
msgstr ""
#: src/cmd/install.c:85 src/cmd/remove.c:72 src/cmd/update.c:67
msgid "Operation cancelled"
msgstr ""
#: src/cmd/install.c:91
#, c-format
msgid "(%d/%d) Downloading "
msgstr ""
#: src/cmd/install.c:85
#: src/cmd/install.c:97
#, fuzzy
msgid "Failed to download "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:97
#: src/cmd/install.c:106 src/cmd/update.c:27
#, c-format
msgid "(%d/%d) Installing "
msgstr ""
#: src/cmd/install.c:100
#: src/cmd/install.c:112
#, fuzzy
msgid "Failed to install "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/install.c:118
#, c-format
msgid "Installed %d package"
msgstr ""
#: src/cmd/install.c:118
#, c-format
msgid "Installed all of the %d packages"
msgstr ""
#: src/cmd/list.c:12
msgid "Listing options for the install command:"
msgid "Listing options for the list command:"
msgstr ""
#: src/cmd/list.c:23
@ -191,39 +222,84 @@ msgid "There no installed packages"
msgstr ""
#: src/cmd/list.c:28
#, c-format
msgid "Listing %d packages"
msgid "Listing "
msgstr ""
#: src/cmd/list.c:28
#, c-format
msgid "Listing %d package"
#: src/cmd/remove.c:16
msgid "Listing options for the remove command:"
msgstr ""
#: src/cmd/sync.c:20
#: src/cmd/remove.c:49
#, fuzzy
msgid "Cannot remove "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/remove.c:57
msgid "Nothing to do (no packages to remove)"
msgstr ""
#: src/cmd/remove.c:79 src/cmd/update.c:20
#, c-format
msgid "(%d/%d) Removing "
msgstr ""
#: src/cmd/remove.c:85
#, fuzzy
msgid "Failed to remove "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/remove.c:91
#, c-format
msgid "Removed %d package"
msgstr ""
#: src/cmd/remove.c:91
#, c-format
msgid "Removed all of the %d packages"
msgstr ""
#: src/cmd/sync.c:19
#, fuzzy
msgid "Failed to sync "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/sync.c:29 src/cmd/sync.c:56
#: src/cmd/sync.c:28 src/cmd/sync.c:58
msgid "Synced "
msgstr ""
#: src/cmd/sync.c:35
#: src/cmd/sync.c:34
#, fuzzy, c-format
msgid "Failed to sync %s: %s"
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/sync.c:47
#: src/cmd/sync.c:46
#, fuzzy
msgid "There are no pools specified in the configuration"
msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
#: src/cmd/sync.c:52
#: src/cmd/sync.c:54
#, fuzzy, c-format
msgid "Failed to sync pools: %s"
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/cmd/update.c:38
msgid "Listing options for the update command:"
msgstr ""
#: src/cmd/update.c:50
#, 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:55
msgid "All packages are up-to-date"
msgstr ""
#: src/cmd/update.c:79
#, fuzzy
msgid "Failed to update "
msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#, fuzzy
#~ msgid "Syncing "
#~ msgstr "%lu tane havuz %s adresinde sunuluyor"
@ -244,10 +320,6 @@ msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#~ msgid "%s: successfuly loaded the package list"
#~ msgstr "%s: paket listesi başarıyla yüklendi"
#, c-format
#~ msgid "%s: failed to load the package list (%s)"
#~ msgstr "%s: paket listesini yüklemek başarısız oldu (%s)"
#~ msgid "Configuration file not specified"
#~ msgstr "Konfigürasyon dosyası belirtilmedi"

View File

@ -1,6 +1,4 @@
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/error.h>
#include <stdio.h>
#include "../util.h"
@ -19,15 +17,22 @@ bool cmd_download_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, size_t
}
bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
if(args_get_bool(args, "help")){
info(_("Listing options for the install command:"));
printf(_(" "FG_BOLD"--continue"FG_RESET":\tcontinue even if package is not found\n"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
return true;
}
lm_ctx_resolve_list_t *list = NULL;
ssize_t current = 1, size = 0;
bool ret = false, r = false;
ssize_t current = 0, size = 0;
char ssize[LONGSTR_MAX+3];
lm_pkg_t *pkg = NULL;
char *name = NULL;
bool ret = false;
if(lm_ctx_sync(ctx, false, NULL, NULL) <= 0){
error(_("There are no avaliable pools"));
error(_("There are no avaliable pools, have you synced yet?"));
goto end;
}
@ -41,12 +46,14 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
// find the package
if((pkg = lm_ctx_pool_find(ctx, name, NULL)) == NULL){
error(_("Failed to find "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror());
goto end;
if(args_get_bool(args, "continue"))
continue;
else
goto end;
}
// WEIRD CRASH HERE
if(lm_ctx_database_is_installed(ctx, pkg, true)){
error(_("Package "FG_BOLD"%s"FG_RESET" ("FG_BLUE"%s"FG_RESET") is already installed"));
error(_("Package "FG_BOLD"%s"FG_RESET" ("FG_BLUE"%s"FG_RESET") is already installed"), name, pkg->version);
goto end;
}
@ -58,7 +65,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(NULL == list){
error(_("Please specify at least one package to install"));
error(_("Nothing to do (no packages to install)"));
goto end;
}
@ -66,46 +73,49 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
size += pkg->size;
size_to_human(ssize, size);
info(_("Following packages will be "FG_BOLD"INSTALLED:"FG_RESET));
if(list->count == 1)
info(_("Following %d package will be "FG_BOLD"INSTALLED:"FG_RESET), list->count);
else
info(_("Following %d packages will be "FG_BOLD"INSTALLED:"FG_RESET), list->count);
// list all the packages
info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be used"), ssize);
if(!yesno("Continue?")){
error("Operation cancelled");
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled"));
goto end;
}
// download resolved packages
while((pkg = lm_ctx_resolve_next(list)) != NULL){
info(_("(%d/%d) Downloading "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), current, list->count, pkg->name, pkg->version);
info(_("(%d/%d) Downloading "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), ++current, list->count, pkg->name, pkg->version);
if(!lm_ctx_download(ctx, pkg, cmd_download_callback, NULL)){
r = lm_ctx_download(ctx, pkg, cmd_download_callback, NULL);
bar_free();
if(!r){
error(_("Failed to download "FG_BOLD"%s"FG_RESET": %s"), pkg->name, lm_strerror());
goto end;
}
current++;
bar_free();
}
current = 1;
current = 0;
// install resolved packages
while((pkg = lm_ctx_resolve_next(list)) != NULL){
info(_("(%d/%d) Installing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), current, list->count, pkg->name, pkg->version);
info(_("(%d/%d) Installing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), ++current, list->count, pkg->name, pkg->version);
if(!lm_ctx_install(ctx, pkg, cmd_install_callback, NULL)){
r = lm_ctx_install(ctx, pkg, cmd_install_callback, NULL);
bar_free();
if(!r){
error(_("Failed to install "FG_BOLD"%s"FG_RESET": %s"), pkg->name, lm_strerror());
goto end;
}
current++;
bar_free();
}
if(current == list->count){
success("Installed all of the %d packages", list->count);
success(list->count == 1 ? _("Installed %d package") : _("Installed all of the %d packages"), list->count);
ret = true;
}

View File

@ -9,7 +9,7 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
lm_pkg_t pkg;
if(args_get_bool(args, "help")){
info(_("Listing options for the install command:"));
info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n"));
printf(_(" "FG_BOLD"--desc"FG_RESET":\tshow package descriptions\n"));
return true;
@ -25,7 +25,7 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(!args_get_bool(args, "grep"))
info(count > 1 ? _("Listing %d packages") : _("Listing %d package"));
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)){
if(args_get_bool(args, "grep")){
@ -33,12 +33,13 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
printf("%s:%s:%s\n", pkg.name, pkg.version, pkg.desc);
else
printf("%s:%s\n", pkg.name, pkg.version);
continue;
}
if(args_get_bool(args, "desc"))
printf(FG_BOLD"%s ("FG_BLUE"%s"FG_RESET"): %s\n", pkg.name, pkg.version, pkg.desc);
printf(FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET"): %s\n", pkg.name, pkg.version, pkg.desc);
else
printf(FG_BOLD"%s ("FG_BLUE"%s"FG_RESET")\n", pkg.name, pkg.version);
printf(FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")\n", pkg.name, pkg.version);
}
lm_ctx_database_next_free(ctx, &pkg);

102
src/cmd/remove.c Normal file
View File

@ -0,0 +1,102 @@
#include <libmp/all.h>
#include <stdlib.h>
#include <stdio.h>
#include "../util.h"
#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){
bar(current, total);
return true;
}
bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
if(args_get_bool(args, "help")){
info(_("Listing options for the remove command:"));
printf(_(" "FG_BOLD"--break"FG_RESET":\tbreak other package depends\n"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
return true;
}
ssize_t count = 0, size = 0, current = 0;
bool ret = false, r = false;
char ssize[LONGSTR_MAX+3];
lm_pkg_t *pkgs = NULL;
char *name = NULL;
for(int i = 0; i < args->count; i++){
if(NULL != args->list[i].name)
continue;
if(eq((name = args->list[i].value), "remove"))
continue;
if(NULL == pkgs)
pkgs = malloc(sizeof(lm_pkg_t));
else
pkgs = realloc(pkgs, sizeof(lm_pkg_t)*(count+1));
if(!lm_ctx_database_find(ctx, &pkgs[count++], name, NULL)){
if(lm_error() == LM_ERR_DbSqlNotFound)
error(_("Package "FG_BOLD"%s"FG_RESET" is not installed"), name);
else
error(_("Failed to find "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror());
goto end;
}
if(!lm_ctx_removeable(ctx, &pkgs[count-1])){
error(_("Cannot remove "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET"): %s"), pkgs[count-1].name, pkgs[count-1].version, lm_strerror());
goto end;
}
size += pkgs[count].size;
}
if(NULL == pkgs){
error(_("Nothing to do (no packages to remove)"));
goto end;
}
size_to_human(ssize, size);
if(count == 1)
info(_("Following %d package will be "FG_BOLD"REMOVED:"FG_RESET), count);
else
info(_("Following %d packages will be "FG_BOLD"REMOVED:"FG_RESET), count);
// list all the packages
info(_("Total of "FG_BOLD"%s"FG_RESET" disk space will be freed"), ssize);
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled"));
goto end;
}
for(int i = 0; i < count; i++){
lm_pkg_t *cur = &pkgs[i];
info(_("(%d/%d) Removing "FG_BOLD"%s"FG_RESET" ("FG_BOLD FG_BLUE"%s"FG_RESET")"), ++current, count, cur->name, cur->version);
r = lm_ctx_remove(ctx, cur, cmd_remove_callback, NULL);
bar_free();
if(!r){
error(_("Failed to remove "FG_BOLD"%s"FG_RESET": %s"), cur->name, lm_strerror());
goto end;
}
}
if(current == count){
success(count == 1 ? _("Removed %d package") : _("Removed all of the %d packages"), count);
ret = true;
}
ret = true;
end:
if(NULL != pkgs)
for(int i = 0; i < count; i++)
lm_package_free(&pkgs[i]);
bar_free();
return ret;
}

View File

@ -1,5 +1,4 @@
#include <libmp/all.h>
#include <libmp/error.h>
#include <stdio.h>
#include "../cmd.h"
@ -43,12 +42,15 @@ bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args){
size_t sycned = 0;
bool ret = false;
if(0 == config->pool_count){
if(config->pool_count == 0){
error(_("There are no pools specified in the configuration"));
goto end;
}
if((sycned = lm_ctx_sync(ctx, true, cmd_sync_callback, NULL) < 0)){
sycned = lm_ctx_sync(ctx, true, cmd_sync_callback, NULL);
bar_free();
if(sycned < 0){
error(_("Failed to sync pools: %s"), lm_strerror());
goto end;
}

88
src/cmd/update.c Normal file
View File

@ -0,0 +1,88 @@
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/error.h>
#include <stdio.h>
#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, 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);
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;
}
bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
if(args_get_bool(args, "help")){
info(_("Listing options for the update command:"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
return true;
}
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){
error(_("Failed to get the package update list: %s"), lm_strerror());
goto end;
}
if(list->count == 0){
error(_("All packages are up-to-date"));
goto end;
}
if(list->count == 1)
info(_("Following %d package will be "FG_BOLD"UPDATED:"FG_RESET), list->count);
else
info(_("Following %d packages will be "FG_BOLD"UPDATED:"FG_RESET), list->count);
// list all the packages
if(!args_get_bool(args, "yes") && !yesno(_("Continue?"))){
error(_("Operation cancelled"));
goto end;
}
while((pkg = lm_ctx_update_list_next(list)) != NULL){
cbdata.current = ++current;
cbdata.total = list->count;
r = lm_ctx_update(ctx, pkg, cmd_update_callback, &cbdata);
bar_free();
if(!r){
error(_("Failed to update "FG_BOLD"%s"FG_RESET": %s"), pkg->name, lm_strerror());
goto end;
}
}
ret = true;
end:
lm_ctx_update_list_free(list);
return ret;
}

View File

@ -40,8 +40,8 @@ int main(int argc, char *argv[]) {
{.name = "list", .desc = "list all the installed packages", .func = cmd_list },
{.name = "sync", .desc = "update the pool info and package lists", .func = cmd_sync },
{.name = "install", .desc = "install package(s) from remote pools", .func = cmd_install},
{.name = "remove", .desc = "remove installed package(s)", .func = NULL },
{.name = "update", .desc = "update installed package(s)", .func = NULL },
{.name = "remove", .desc = "remove installed package(s)", .func = cmd_remove },
{.name = "update", .desc = "update installed package(s)", .func = cmd_update },
};
char *config_file = NULL, *root_dir = NULL;