Compare commits

...

11 Commits

12 changed files with 506 additions and 180 deletions

View File

@ -11,7 +11,7 @@ OBJS = $(patsubst src/%.c,dist/%.o,$(SRCS))
CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection
LIBS = -linih -lmp
VERSION = 24.02
VERSION = 24.04
all: dist dist/matt $(PO_OUTS)

View File

@ -8,20 +8,20 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-16 03:44+0300\n"
"POT-Creation-Date: 2024-08-25 22:43+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"
"Language: tr\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/callback.c:34 src/callback.c:49
#: src/callback.c:39 src/callback.c:56
msgid "Failed to sync "
msgstr "Failed to sync "
#: src/callback.c:43 src/cmd/sync.c:32
#: src/callback.c:50 src/cmd/sync.c:46
msgid "Synced "
msgstr "Synced "
@ -31,9 +31,8 @@ msgid "Unknown configuration option: %s/%s"
msgstr "Unknown configuration option: %s/%s"
#: src/config.c:79
#, fuzzy
msgid "Failed to access the configuration file: "
msgstr "Failed to access the configuration file: %s"
msgstr "Failed to access the configuration file: "
#: src/config.c:84
msgid "Failed to parse the configuration"
@ -77,85 +76,115 @@ msgstr "%s [y/N] "
msgid "Please answer with y/n"
msgstr "Please answer with y/n"
#: src/main.c:48
#: src/main.c:49
msgid "Received a segfault"
msgstr "Received a segfault"
#: src/main.c:102
msgid "Failed to lock, matt is already running"
msgstr "Failed to lock, matt is already running"
#: src/main.c:64
#, fuzzy
msgid "show information about a single package"
msgstr "show information about a single package"
#: src/main.c:106
msgid "Failed to lock, are you root?"
msgstr "Failed to lock, are you root?"
#: src/main.c:65
msgid "list all the installed packages"
msgstr "list all the installed packages"
#: src/main.c:130
#: src/main.c:66
msgid "search for packages by name/desc/version"
msgstr ""
#: src/main.c:67
msgid "update the pool info and package lists"
msgstr "update the pool info and package lists"
#: src/main.c:68
msgid "install package(s) from remote pools"
msgstr "install package(s) from remote pools"
#: src/main.c:69
msgid "remove installed package(s)"
msgstr "remove installed package(s)"
#: src/main.c:70
msgid "update installed package(s)"
msgstr "update installed package(s)"
#: src/main.c:119
msgid "Failed to access the root directory, are you running as root?"
msgstr "Failed to access the root directory, are you running as root?"
#: src/main.c:134
#, fuzzy
#: src/main.c:123
msgid "Failed to access the data directory ("
msgstr "Failed to access the configuration file: %s"
msgstr "Failed to access the data directory ("
#: src/main.c:138
#, fuzzy
#: src/main.c:127
msgid "Failed to access the temp directory ("
msgstr "Failed to open the editor: %s"
msgstr "Failed to access the temp directory ("
#: src/main.c:131
#, c-format
msgid "Failed to initialize libmp context: %s"
msgstr "Failed to initialize libmp context: %s"
#: src/main.c:142
#, fuzzy, c-format
msgid "Failed to initialize libmp context: %s"
msgstr "Failed to install "
#: src/main.c:153
#, fuzzy
msgid "Failed to create the pools directory ("
msgstr "Failed to open the editor: %s"
msgstr "Failed to create the pools directory ("
#: src/main.c:163
#: src/main.c:152
msgid "Failed to add pool "
msgstr "Failed to add pool "
#: src/main.c:177
#: src/main.c:166
msgid "Failed to lock, matt is already running"
msgstr "Failed to lock, matt is already running"
#: src/main.c:170
msgid "Failed to lock, are you root?"
msgstr "Failed to lock, are you root?"
#: src/main.c:183
msgid "Command not found: "
msgstr "Command not found: "
#: src/main.c:178
#: src/main.c:184
msgid "Displaying help information"
msgstr ""
msgstr "Displaying help information"
#: src/main.c:181
#, fuzzy, c-format
#: src/main.c:187
#, c-format
msgid "MatterLinux package manager %s (libmp %s)"
msgstr "MatterLinux package manager (version %s)"
msgstr "MatterLinux package manager %s (libmp %s)"
#: src/main.c:182
#: src/main.c:188 src/cmd/info.c:47 src/cmd/install.c:33 src/cmd/list.c:23
#: src/cmd/remove.c:27 src/cmd/search.c:197 src/cmd/sync.c:23
#: src/cmd/update.c:22
msgid "Usage: "
msgstr "Usage: "
#: src/main.c:184
#: src/main.c:190
msgid "Here is a list of available commands:"
msgstr "Here is a list of available commands:"
#: src/main.c:190
#: src/main.c:196
msgid "To list different options, use commands with "
msgstr "To list different options, use commands with "
#: src/main.c:191
#: src/main.c:197
msgid "Here is a list of available global options:"
msgstr "Here is a list of available global options:"
#: src/main.c:194 src/main.c:195 src/cmd/info.c:54 src/cmd/info.c:55
#: src/cmd/info.c:56 src/cmd/install.c:34 src/cmd/install.c:35
#: src/main.c:200 src/main.c:201 src/main.c:202 src/cmd/info.c:49
#: src/cmd/info.c:50 src/cmd/info.c:51 src/cmd/install.c:35
#: src/cmd/install.c:36 src/cmd/install.c:37 src/cmd/install.c:38
#: src/cmd/list.c:24 src/cmd/list.c:25 src/cmd/remove.c:28 src/cmd/remove.c:29
#: src/cmd/update.c:23
#: src/cmd/install.c:39 src/cmd/list.c:25 src/cmd/list.c:26 src/cmd/remove.c:29
#: src/cmd/remove.c:30 src/cmd/search.c:199 src/cmd/search.c:200
#: src/cmd/search.c:201 src/cmd/search.c:202 src/cmd/sync.c:25
#: src/cmd/update.c:24
#, c-format
msgid " "
msgstr " "
#: src/main.c:197
#: src/main.c:204
msgid ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
msgstr ""
@ -175,70 +204,75 @@ msgstr "Failed to run the editor: %s"
msgid "Failed to open the editor: %s"
msgstr "Failed to open the editor: %s"
#: src/cmd/info.c:19 src/cmd/info.c:29 src/cmd/install.c:91 src/cmd/remove.c:52
#: src/cmd/info.c:13 src/cmd/info.c:23 src/cmd/install.c:94 src/cmd/remove.c:53
msgid "Package "
msgstr "Package "
#: src/cmd/info.c:48 src/cmd/install.c:28 src/cmd/list.c:18 src/cmd/remove.c:22
#: src/cmd/sync.c:15 src/cmd/update.c:17
#: src/cmd/info.c:42 src/cmd/install.c:28 src/cmd/list.c:18 src/cmd/remove.c:22
#: src/cmd/search.c:192 src/cmd/sync.c:18 src/cmd/update.c:17
msgid "Unknown argument: "
msgstr ""
msgstr "Unknown argument: "
#: src/cmd/info.c:53 src/cmd/list.c:23
#: src/cmd/info.c:48 src/cmd/list.c:24 src/cmd/search.c:198 src/cmd/sync.c:24
msgid "Listing options for the list command:"
msgstr "Listing options for the list command:"
#: src/cmd/info.c:76
#: src/cmd/info.c:72
msgid "Please specify only a single package name"
msgstr "Please specify only a single package name"
#: src/cmd/info.c:83
#: src/cmd/info.c:79
msgid "Please specify a single package"
msgstr "Please specify a single package"
#: src/cmd/info.c:98
#: src/cmd/info.c:94
msgid "Failed to get the changes file for "
msgstr "Failed to get the changes file for "
#: src/cmd/info.c:104
#: src/cmd/info.c:100
msgid "Failed to access the changes file, is the package installed?"
msgstr "Failed to access the changes file, is the package installed?"
#: src/cmd/info.c:111
#: src/cmd/info.c:107
msgid "Failed to get the depends list for "
msgstr "Failed to get the depends list for "
#: src/cmd/info.c:138
#: src/cmd/info.c:135
#, c-format
msgid "Name "
msgstr "Name "
#: src/cmd/info.c:139
#: src/cmd/info.c:136
#, c-format
msgid "Version "
msgstr "Version "
#: src/cmd/info.c:140
#: src/cmd/info.c:137
#, c-format
msgid "Desc "
msgstr "Desc "
#: src/cmd/info.c:141
#: src/cmd/info.c:138
#, c-format
msgid "Size "
msgstr "Size "
#: src/cmd/info.c:144
#: src/cmd/info.c:141
#, c-format
msgid "Depends "
msgstr "Depends "
#: src/cmd/info.c:147
#: src/cmd/info.c:144
#, c-format
msgid "Changes "
msgstr "Changes "
#: src/cmd/info.c:151 src/cmd/info.c:152
#: src/cmd/info.c:147
#, fuzzy, c-format
msgid "Pool "
msgstr " "
#: src/cmd/info.c:150 src/cmd/info.c:151
#, c-format
msgid "Installed "
msgstr "Installed "
@ -248,149 +282,162 @@ msgstr "Installed "
msgid "Up-to-date "
msgstr "Up-to-date "
#: src/cmd/install.c:33
#: src/cmd/install.c:34
msgid "Listing options for the install command:"
msgstr "Listing options for the install command:"
#: src/cmd/install.c:43 src/cmd/update.c:28
#: src/cmd/install.c:44 src/cmd/update.c:29
msgid "There are no avaliable pools, have you synced yet?"
msgstr "There are no avaliable pools, have you synced yet?"
#: src/cmd/install.c:62
#: src/cmd/install.c:63
msgid "Specified "
msgstr ""
msgstr "Specified "
#: src/cmd/install.c:72
#, fuzzy
#: src/cmd/install.c:76
msgid "Failed to load "
msgstr "Failed to download "
msgstr "Failed to load "
#: src/cmd/install.c:82 src/cmd/remove.c:54
#: src/cmd/install.c:85 src/cmd/remove.c:55
msgid "Failed to find "
msgstr "Failed to find "
#: src/cmd/install.c:100
#: src/cmd/install.c:103
msgid "Failed to resolve "
msgstr "Failed to resolve "
#: src/cmd/install.c:109
#: src/cmd/install.c:112
msgid "Nothing to do (no packages to install)"
msgstr "Nothing to do (no packages to install)"
#: src/cmd/install.c:118 src/cmd/install.c:120 src/cmd/remove.c:74
#: src/cmd/remove.c:76 src/cmd/update.c:49 src/cmd/update.c:51
#: src/cmd/install.c:121 src/cmd/install.c:123 src/cmd/remove.c:75
#: src/cmd/remove.c:77 src/cmd/update.c:50 src/cmd/update.c:52
msgid "Following "
msgstr "Following "
#: src/cmd/install.c:126 src/cmd/remove.c:83
#: src/cmd/install.c:129 src/cmd/remove.c:84
msgid "Total of "
msgstr "Total of "
#: src/cmd/install.c:129 src/cmd/update.c:58
#: src/cmd/install.c:132 src/cmd/update.c:59
#, c-format
msgid "Root directory is modified, install scripts will be saved in %s"
msgstr "Root directory is modified, install scripts will be saved in %s"
#: src/cmd/install.c:131 src/cmd/remove.c:84 src/cmd/update.c:60
#: src/cmd/install.c:134 src/cmd/remove.c:85 src/cmd/update.c:61
msgid "Continue?"
msgstr "Continue?"
#: src/cmd/install.c:132 src/cmd/remove.c:85 src/cmd/update.c:61
#: src/cmd/install.c:135 src/cmd/remove.c:86 src/cmd/update.c:62
msgid "Operation cancelled"
msgstr "Operation cancelled"
#: src/cmd/install.c:148 src/cmd/install.c:152 src/cmd/install.c:172
#: src/cmd/install.c:188 src/cmd/remove.c:92 src/cmd/update.c:71
#: src/cmd/update.c:82 src/cmd/update.c:93
#: src/cmd/install.c:151 src/cmd/install.c:155 src/cmd/install.c:175
#: src/cmd/install.c:191 src/cmd/remove.c:93 src/cmd/update.c:72
#: src/cmd/update.c:83 src/cmd/update.c:94
msgid "("
msgstr "("
#: src/cmd/install.c:158 src/cmd/update.c:77
#: src/cmd/install.c:161 src/cmd/update.c:78
msgid "Failed to download "
msgstr "Failed to download "
#: src/cmd/install.c:179 src/cmd/remove.c:59 src/cmd/remove.c:99
#: src/cmd/update.c:88
#: src/cmd/install.c:182 src/cmd/remove.c:100 src/cmd/update.c:89
msgid "Failed to remove "
msgstr "Failed to remove "
#: src/cmd/install.c:195 src/cmd/update.c:99
#: src/cmd/install.c:198 src/cmd/update.c:100
msgid "Failed to install "
msgstr "Failed to install "
#: src/cmd/install.c:202
#: src/cmd/install.c:205
msgid "Installed "
msgstr "Installed "
#: src/cmd/install.c:202
#: src/cmd/install.c:205
msgid "Installed all of the "
msgstr "Installed all of the "
#: src/cmd/list.c:38
msgid "There no installed packages"
#: src/cmd/list.c:39
#, fuzzy
msgid "There are no installed packages"
msgstr "There no installed packages"
#: src/cmd/list.c:43
#: src/cmd/list.c:44
msgid "Listing "
msgstr "Listing "
#: src/cmd/remove.c:27
#: src/cmd/remove.c:28
msgid "Listing options for the remove command:"
msgstr "Listing options for the remove command:"
#: src/cmd/remove.c:67
#: src/cmd/remove.c:60
#, fuzzy
msgid "Cannot remove "
msgstr "Failed to remove "
#: src/cmd/remove.c:68
msgid "Nothing to do (no packages to remove)"
msgstr "Nothing to do (no packages to remove)"
#: src/cmd/remove.c:106
#: src/cmd/remove.c:107
msgid "Removed "
msgstr "Removed "
#: src/cmd/remove.c:106
#: src/cmd/remove.c:107
msgid "Removed all of the "
msgstr "Removed all of the "
#: src/cmd/sync.c:20
#: src/cmd/search.c:72 src/cmd/search.c:149
msgid "No results, maybe you forgot to sync?"
msgstr ""
#: src/cmd/search.c:77 src/cmd/search.c:154
msgid "Found "
msgstr ""
#: src/cmd/search.c:113
#, fuzzy, c-format
msgid "Failed to load package pools: %s"
msgstr "Failed to get the package update list: %s"
#: src/cmd/search.c:119
#, fuzzy, c-format
msgid "Failed to get package list: %s"
msgstr "Failed to get the package update list: %s"
#: src/cmd/search.c:218
#, fuzzy
msgid "Please specify only a single query for searching"
msgstr "Please specify only a single package name"
#: src/cmd/search.c:225
#, fuzzy
msgid "Please specify a query for searching"
msgstr "Please specify a single package"
#: src/cmd/sync.c:30
msgid "There are no pools specified in the configuration"
msgstr "There are no pools specified in the configuration"
#: src/cmd/sync.c:28
#: src/cmd/sync.c:39
#, c-format
msgid "Failed to sync pools: %s"
msgstr "Failed to sync pools: %s"
#: src/cmd/update.c:22
#: src/cmd/update.c:23
msgid "Listing options for the update command:"
msgstr "Listing options for the update command:"
#: src/cmd/update.c:39
#: src/cmd/update.c:40
#, c-format
msgid "Failed to get the package update list: %s"
msgstr "Failed to get the package update list: %s"
#: src/cmd/update.c:44
#: src/cmd/update.c:45
msgid "All packages are up-to-date"
msgstr "All packages are up-to-date"
#: src/cmd/update.c:67
#: src/cmd/update.c:68
msgid "Failed to update "
msgstr "Failed to update "
#~ msgid "Cannot remove "
#~ msgstr "Cannot remove "
#, c-format
#~ msgid "Failed to sync %s: %s"
#~ msgstr "Failed to sync %s: %s"
#, c-format
#~ msgid "Bad root directory (%s): %s"
#~ msgstr "Bad root directory (%s): %s"
#, c-format
#~ msgid "Bad datadir (%s): %s"
#~ msgstr "Bad datadir (%s): %s"
#, c-format
#~ msgid "Bad tmpdir (%s): %s"
#~ msgstr "Bad tmpdir (%s): %s"

View File

@ -3,7 +3,10 @@
#include "log.h"
bool callback_install(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data) {
if (current < total)
bar(current, total);
else
bar_free();
return true;
}
@ -20,6 +23,8 @@ bool callback_remove(lm_ctx_t *ctx, lm_entry_t *ent, char *file, size_t current,
bool callback_sync(
lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data) {
bool fail = *(bool *)data;
switch (state) {
case SYNC_DOWNLOADING_INFO:
bar(current, total);
@ -32,6 +37,8 @@ bool callback_sync(
case SYNC_INFO_FAIL:
bar_free();
error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror());
if (fail)
return false;
break;
case SYNC_DOWNLOADING_LIST:
@ -47,6 +54,8 @@ bool callback_sync(
bar_free();
if (LM_ERR_InfoNotLoaded != lm_error())
error(_("Failed to sync " FG_BOLD "%s" FG_RESET ": %s"), pool->name, lm_strerror());
if (fail)
return false;
break;
}

View File

@ -17,6 +17,7 @@ typedef struct cmd {
bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args);
bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args);

View File

@ -1,26 +1,20 @@
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/database.h>
#include <libmp/error.h>
#include <libmp/package.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include "../util.h"
#include "../intl.h"
#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){
lm_pkg_data_t *cmd_info_from_pool(lm_ctx_t *ctx, lm_pkg_t **pkgp, args_t *args, char *name){
if((*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 NULL;
}
return &pkg->data;
return &(*pkgp)->data;
}
lm_pkg_data_t *cmd_info_from_database(lm_ctx_t *ctx, lm_entry_t *entry, args_t *args, char *name){
@ -50,6 +44,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "info <options> [package name]"));
info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n"));
printf(_(" "FG_BOLD"--changes"FG_RESET":\topen the changes file for the package\n"));
@ -62,6 +57,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
char *name = NULL, *depends = NULL, *changes = NULL;
lm_pkg_data_t *data = NULL;
lm_pkg_t *pkg = NULL;
lm_entry_t ent;
for(size_t i = 1; i < args->count; i++){
@ -90,7 +86,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
}
else if(!args_get_bool(args, "database")){
if((data = cmd_info_from_pool(ctx, args, name)) == NULL)
if((data = cmd_info_from_pool(ctx, &pkg, args, name)) == NULL)
return false;
}
@ -125,6 +121,7 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
printf("CHANGES:%s\n", changes);
if(!args_get_bool(args, "database")){
printf("POOL:%s\n", pkg->pool->name);
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));
}
@ -147,9 +144,12 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
printf(_(FG_BOLD"Changes "FG_BLUE"=>"FG_RESET" %s\n"), changes);
if(!args_get_bool(args, "database")){
printf(_(FG_BOLD"Pool "FG_BLUE"=>"FG_RESET" %s\n"), pkg->pool->name);
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, 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"));

View File

@ -30,6 +30,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "install <options> [package name(s)]"));
info(_("Listing options for the install command:"));
printf(_(" "FG_BOLD"--ignore-depends"FG_RESET":\tignore package dependencies\n"));
printf(_(" "FG_BOLD"--ignore-none"FG_RESET":\tignore if there is nothing do\n"));
@ -46,7 +47,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
ssize_t current = 0, size = 0, save = 0, li = 0;
bool ret = false, r = false, is_local = false;
lm_pkg_t *pkg = NULL, *locals = NULL;
lm_pkg_t *pkg = NULL, **locals = NULL;
lm_ctx_resolve_list_t *list = NULL;
lm_entry_t older;
char ssize[LONGSTR_MAX+3];
@ -56,7 +57,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
if(NULL != args->list[i].name || NULL == (name = args->list[i].value))
continue;
// if thiş is a local archive, load it
// if this is a local archive, load it
if(endswith(name, ".mpf") && access(name, F_OK) == 0){
if(access(name, R_OK) != 0){
error(_("Specified "FG_BOLD"%s"FG_RESET" archive does not have read access"), name);
@ -64,16 +65,18 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(NULL == locals)
locals = malloc(sizeof(lm_pkg_t));
locals = malloc(sizeof(lm_pkg_t*));
else
locals = realloc(locals, sizeof(lm_pkg_t)*((++li)+1));
locals = realloc(locals, sizeof(lm_pkg_t*)*((++li)+1));
if(!lm_ctx_package_from(ctx, &locals[li], name)){
pkg = malloc(sizeof(lm_pkg_t));
locals[li] = pkg;
if(!lm_ctx_package_from(ctx, pkg, name)){
error(_("Failed to load "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror());
goto end;
}
pkg = &locals[li];
goto resolve;
}
@ -138,7 +141,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
is_local = false;
for(size_t i = 0; i < (li+1) && NULL != locals; i++){
if(lm_package_is_same(&locals[i], pkg)){
if(lm_package_is_same(locals[i], pkg)){
is_local = true;
break;
}
@ -207,7 +210,7 @@ end:
bar_free();
for(size_t i = 0; i < (li+1) && NULL != locals; i++)
lm_ctx_package_from_free(&locals[li]);
lm_ctx_package_from_free(locals[li]);
free(locals);
lm_ctx_resolve_free(list);

View File

@ -20,6 +20,7 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "list <options>"));
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"));
@ -35,7 +36,7 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
if(count <= 0){
if(!args_get_bool(args, "grep"))
info(_("There no installed packages"));
info(_("There are no installed packages"));
return true;
}
@ -52,9 +53,11 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "desc"))
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s\n", ent.name, ent.version, ent.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", ent.name, ent.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, &ent);

View File

@ -24,6 +24,7 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "remove <options> [package name(s)]"));
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"));
@ -55,12 +56,12 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
goto end;
}
if(!lm_ctx_removeable(ctx, &pkgs[count-1])){
error(_("Failed to remove "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgs[count-1].name, pkgs[count-1].version, lm_strerror());
if(!args_get_bool(args, "break") && !lm_ctx_removeable(ctx, &pkgs[count-1])){
error(_("Cannot remove "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgs[count-1].name, pkgs[count-1].version, lm_strerror());
goto end;
}
size += pkgs[count].size;
size += pkgs[count-1].size;
}
if(NULL == pkgs){

240
src/cmd/search.c Normal file
View File

@ -0,0 +1,240 @@
#include <libmp/all.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "../util.h"
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"
enum field {
FIELD_NAME = 0,
FIELD_DESC = 1,
FIELD_VERSION = 2,
};
bool contains(char *string, char *search){
if(NULL == string || NULL == search)
return false;
size_t string_size = strlen(string);
size_t search_size = strlen(search);
size_t i = 0;
char string_lower[string_size+1];
char search_lower[search_size+1];
for(i = 0; i < string_size; i++)
string_lower[i] = tolower(string[i]);
string_lower[i] = 0;
for(i = 0; i < search_size; i++)
search_lower[i] = tolower(search[i]);
search_lower[i] = 0;
return strstr(string_lower, search_lower) != NULL;
}
bool cmd_search_database(lm_ctx_t *ctx, args_t *args, char *query, enum field field) {
lm_entry_t *list = malloc(sizeof(lm_entry_t));
char *selected = NULL;
size_t indx = 0, i = 0;
bool ret = false;
while(lm_ctx_database_next(ctx, &list[indx])){
selected = NULL;
switch (field) {
case FIELD_NAME:
selected = list[indx].name;
break;
case FIELD_DESC:
selected = list[indx].desc;
break;
case FIELD_VERSION:
selected = list[indx].version;
break;
}
if(!contains(selected, query))
continue;
list = realloc(list, sizeof(lm_entry_t)*((++indx)+1));
lm_entry_init(&list[indx]);
}
if(indx <= 0){
if(!args_get_bool(args, "grep"))
info(_("No results, maybe you forgot to sync?"));
goto end;
}
if(!args_get_bool(args, "grep"))
info(indx > 1 ? _("Found "FG_BOLD"%d"FG_RESET" results") : _("Found "FG_BOLD"%d"FG_RESET" result"), indx);
for(i = 0; i < indx; i++){
if(args_get_bool(args, "grep")){
if(args_get_bool(args, "desc"))
printf("%s:%s:%s\n", list[i].name, list[i].version, list[i].desc);
else
printf("%s:%s\n", list[i].name, list[i].version);
continue;
}
if(args_get_bool(args, "desc"))
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s\n", list[i].name, list[i].version, list[i].desc);
else
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET"\n", list[i].name, list[i].version);
}
ret = true;
end:
for(i = 0; i < (indx+1); i++)
lm_ctx_database_next_free(ctx, &list[indx]);
free(list);
return ret;
}
bool cmd_search_pools(lm_ctx_t *ctx, args_t *args, char *query, enum field field) {
lm_pkg_t **list = malloc(sizeof(lm_pkg_t*));
char *selected = NULL;
size_t indx = 0, i = 0;
lm_ctx_list_t plist;
bool ret = false;
list[indx] = NULL;
if(!lm_ctx_sync(ctx, false, NULL, NULL)){
if(!args_get_bool(args, "grep"))
info(_("Failed to load package pools: %s"), lm_strerror());
goto end;
}
if(!lm_ctx_list(ctx, &plist)){
if(!args_get_bool(args, "grep"))
info(_("Failed to get package list: %s"), lm_strerror());
goto end;
}
while((list[indx] = lm_ctx_list_next(&plist)) != NULL){
selected = NULL;
switch (field) {
case FIELD_NAME:
selected = list[indx]->data.name;
break;
case FIELD_DESC:
selected = list[indx]->data.desc;
break;
case FIELD_VERSION:
selected = list[indx]->data.version;
break;
}
if(!contains(selected, query))
continue;
list = realloc(list, sizeof(lm_pkg_t*)*((++indx)+1));
list[indx] = NULL;
}
if(indx <= 0){
if(!args_get_bool(args, "grep"))
info(_("No results, maybe you forgot to sync?"));
goto end;
}
if(!args_get_bool(args, "grep"))
info(indx > 1 ? _("Found "FG_BOLD"%d"FG_RESET" results") : _("Found "FG_BOLD"%d"FG_RESET" result"), indx);
for(i = 0; i < indx; i++){
if(args_get_bool(args, "grep")){
if(args_get_bool(args, "desc"))
printf("%s:%s:%s\n", list[i]->data.name, list[i]->data.version, list[i]->data.desc);
else
printf("%s:%s\n", list[i]->data.name, list[i]->data.version);
continue;
}
if(args_get_bool(args, "desc"))
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s\n",
list[i]->data.name, list[i]->data.version, list[i]->data.desc);
else
printf(FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET"\n",
list[i]->data.name, list[i]->data.version);
}
end:
lm_ctx_list_free(&plist);
free(list);
return ret;
}
bool cmd_search(lm_ctx_t *ctx, config_t *config, args_t *args){
char *arg = NULL;
args_split(args, "grep");
args_split(args, "desc");
args_split(args, "database");
args_register(args, "grep");
args_register(args, "desc");
args_register(args, "field");
args_register(args, "database");
if((arg = args_register_check(args)) != NULL){
error(_("Unknown argument: "FG_BOLD"--%s"FG_RESET", run with "FG_BOLD"--help"FG_RESET" to list the avaliable arguments"), arg);
return false;
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "search <options> [query]"));
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 description of the results\n"));
printf(_(" "FG_BOLD"--field"FG_RESET":\tpackage field to search by (\"name\", \"desc\" or \"version\")\n"));
printf(_(" "FG_BOLD"--database"FG_RESET":\tsearch the database instead of the pools\n"));
return true;
}
enum field field = FIELD_NAME;
char *query = NULL, *field_val = NULL;
for(size_t i = 1; i < args->count; i++){
if(NULL != args->list[i].name)
continue;
if(NULL == query && NULL != (query = args->list[i].value))
continue;
else if(NULL != query && NULL != (query = args->list[i].value)){
if(!args_get_bool(args, "grep"))
error(_("Please specify only a single query for searching"));
return false;
}
}
if(NULL == query){
if(!args_get_bool(args, "grep"))
error(_("Please specify a query for searching"));
return false;
}
if(NULL == (field_val = args_get_string(args, "field")))
field = FIELD_NAME;
else if(eq(field_val, "desc"))
field = FIELD_DESC;
else if(eq(field_val, "version"))
field = FIELD_VERSION;
if(args_get_bool(args, "database"))
return cmd_search_database(ctx, args, query, field);
return cmd_search_pools(ctx, args, query, field);
}

View File

@ -7,29 +7,43 @@
#include "../log.h"
bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args){
size_t sycned = 0;
bool ret = false;
bool ret = false, fail = false;
ssize_t synced = 0;
char *arg = NULL;
args_split(args, "fail");
args_register(args, "fail");
if((arg = args_register_check(args)) != NULL){
error(_("Unknown argument: "FG_BOLD"--%s"FG_RESET", run with "FG_BOLD"--help"FG_RESET" to list the avaliable arguments"), arg);
return false;
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "sync <options>"));
info(_("Listing options for the list command:"));
printf(_(" "FG_BOLD"--fail"FG_RESET":\tquit on a single pool sync failure\n"));
return true;
}
if(config->pool_count == 0){
error(_("There are no pools specified in the configuration"));
goto end;
}
sycned = lm_ctx_sync(ctx, true, callback_sync, NULL);
fail = args_get_bool(args, "fail");
synced = lm_ctx_sync(ctx, true, callback_sync, &fail);
bar_free();
if(sycned < 0){
if(synced < 0 && !fail){
error(_("Failed to sync pools: %s"), lm_strerror());
goto end;
}
info(_("Synced "FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET" pools"), sycned, config->pool_count);
else if(synced < 0 && fail)
goto end;
info(_("Synced "FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET" pools"), synced, config->pool_count);
ret = true;
end:

View File

@ -19,6 +19,7 @@ bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(args_get_bool(args, "help")){
info(_("Usage: " FG_BOLD "update <options>"));
info(_("Listing options for the update command:"));
printf(_(" "FG_BOLD"--yes"FG_RESET":\tdon't ask for confirmation\n"));
return true;

View File

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "args.h"
#include "cmd.h"
@ -60,17 +61,18 @@ int main(int argc, char *argv[], char *envp[]) {
textdomain("matt");
cmd_t commands[] = {
{.name = "info", .desc = "show information about a single package", .root = false, .func = cmd_info },
{.name = "list", .desc = "list all the installed packages", .root = false, .func = cmd_list },
{.name = "sync", .desc = "update the pool info and package lists", .root = true, .func = cmd_sync },
{.name = "install", .desc = "install package(s) from remote pools", .root = true, .func = cmd_install},
{.name = "remove", .desc = "remove installed package(s)", .root = true, .func = cmd_remove },
{.name = "update", .desc = "update installed package(s)", .root = true, .func = cmd_update },
{.name = "info", .desc = _("show information about a single package"), .root = false, .func = cmd_info },
{.name = "list", .desc = _("list all the installed packages"), .root = false, .func = cmd_list },
{.name = "search", .desc = _("search for packages by name/desc/version"), .root = false, .func = cmd_search },
{.name = "sync", .desc = _("update the pool info and package lists"), .root = true, .func = cmd_sync },
{.name = "install", .desc = _("install package(s) from remote pools"), .root = true, .func = cmd_install},
{.name = "remove", .desc = _("remove installed package(s)"), .root = true, .func = cmd_remove },
{.name = "update", .desc = _("update installed package(s)"), .root = true, .func = cmd_update },
};
char *full_datadir = NULL, *full_tmpdir = NULL, *full_pooldir = NULL;
char *config_file = NULL, *root_dir = NULL, *real_tmpdir = NULL;
bool ret = false, r = false, use_root = false;
char *config_file = NULL, *root_dir = NULL;
cmd_func_t cmd = NULL;
args_t *args = NULL;
config_t config;
@ -88,43 +90,30 @@ int main(int argc, char *argv[], char *envp[]) {
if (!config_load(&ctx, &config, config_file))
goto end;
if (args->count <= 0 || args->list[0].name != NULL)
goto help;
for (int i = 0; i < sizeof(commands) / sizeof(cmd_t); i++) {
if (!eq(commands[i].name, args->list[0].value))
continue;
use_root = commands[i].root;
if (!use_root)
goto skip_lock;
switch (lock(&ctx)) {
case ALREADY_LOCKED:
error(_("Failed to lock, matt is already running"));
goto end;
case LOCK_ERROR:
error(_("Failed to lock, are you root?"));
goto end;
default:
break;
}
skip_lock:
cmd = commands[i].func;
break;
}
if (args->count <= 0 || args->list[0].name != NULL)
goto help;
if ((root_dir = args_get_string(args, "root")) == NULL)
root_dir = "/";
full_datadir = join_alloc(root_dir, config.datadir);
full_tmpdir = join_alloc(root_dir, config.tmpdir);
if (!lm_ctx_new(&ctx, use_root ? root_dir : NULL, full_tmpdir, full_datadir)) {
if (!use_root && access(full_tmpdir, W_OK) != 0)
real_tmpdir = "/tmp/.matt";
else
real_tmpdir = full_tmpdir;
if (!lm_ctx_new(&ctx, use_root ? root_dir : NULL, real_tmpdir, full_datadir)) {
switch (lm_error()) {
case LM_ERR_CtxRootFail:
error(_("Failed to access the root directory, are you running as root?"));
@ -169,6 +158,23 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (NULL != cmd) {
if (!use_root)
goto skip_lock;
switch (lock(&ctx)) {
case ALREADY_LOCKED:
error(_("Failed to lock, matt is already running"));
goto end;
case LOCK_ERROR:
error(_("Failed to lock, are you root?"));
goto end;
default:
break;
}
skip_lock:
ret = cmd(&ctx, &config, args);
unlock(&ctx);
goto end;
@ -192,7 +198,8 @@ help:
printf(
_(" " FG_BOLD "--config" FG_RESET ":\t specify the configuration file (default is /etc/matt/config.ini)\n"));
printf(_(" " FG_BOLD "--root" FG_RESET ":\t specify a custom root directory (default is /)\n\n"));
printf(_(" " FG_BOLD "--root" FG_RESET ":\t specify a custom root directory (default is /)\n"));
printf(_(" " FG_BOLD "--help" FG_RESET ":\t list avaliable options/commands\n\n"));
info(_("Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"));