new: support installing local package archives
This commit is contained in:
parent
049642d06b
commit
43733a2c3e
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-08-04 15:54+0300\n"
|
||||
"POT-Creation-Date: 2024-08-06 04:45+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"
|
||||
@ -135,7 +135,7 @@ msgid "Here is a list of available global options:"
|
||||
msgstr "Here is a list of available global options:"
|
||||
|
||||
#: src/main.c:174 src/main.c:175 src/cmd/info.c:43 src/cmd/info.c:44
|
||||
#: src/cmd/info.c:45 src/cmd/install.c:26 src/cmd/install.c:27
|
||||
#: src/cmd/info.c:45 src/cmd/install.c:31 src/cmd/install.c:32
|
||||
#: src/cmd/list.c:14 src/cmd/list.c:15 src/cmd/remove.c:21 src/cmd/remove.c:22
|
||||
#: src/cmd/update.c:30
|
||||
#, c-format
|
||||
@ -162,7 +162,7 @@ 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:60 src/cmd/remove.c:46
|
||||
#: src/cmd/info.c:19 src/cmd/info.c:29 src/cmd/install.c:84 src/cmd/remove.c:43
|
||||
msgid "Package "
|
||||
msgstr "Package "
|
||||
|
||||
@ -170,7 +170,7 @@ msgstr "Package "
|
||||
msgid "Listing options for the list command:"
|
||||
msgstr "Listing options for the list command:"
|
||||
|
||||
#: src/cmd/info.c:66
|
||||
#: src/cmd/info.c:65
|
||||
msgid "Please specify only a single package name"
|
||||
msgstr "Please specify only a single package name"
|
||||
|
||||
@ -230,66 +230,76 @@ msgstr "Installed "
|
||||
msgid "Up-to-date "
|
||||
msgstr "Up-to-date "
|
||||
|
||||
#: src/cmd/install.c:25
|
||||
#: src/cmd/install.c:30
|
||||
msgid "Listing options for the install command:"
|
||||
msgstr "Listing options for the install command:"
|
||||
|
||||
#: src/cmd/install.c:32 src/cmd/update.c:35
|
||||
#: src/cmd/install.c:37 src/cmd/update.c:35
|
||||
msgid "There are no avaliable pools, have you synced yet?"
|
||||
msgstr "There are no avaliable pools, have you synced yet?"
|
||||
|
||||
#: src/cmd/install.c:52 src/cmd/remove.c:48
|
||||
#: src/cmd/install.c:55
|
||||
msgid "Specified "
|
||||
msgstr ""
|
||||
|
||||
#: src/cmd/install.c:65
|
||||
#, fuzzy
|
||||
msgid "Failed to load "
|
||||
msgstr "Failed to download "
|
||||
|
||||
#: src/cmd/install.c:75 src/cmd/remove.c:45
|
||||
msgid "Failed to find "
|
||||
msgstr "Failed to find "
|
||||
|
||||
#: src/cmd/install.c:66
|
||||
#: src/cmd/install.c:90
|
||||
msgid "Failed to resolve "
|
||||
msgstr "Failed to resolve "
|
||||
|
||||
#: src/cmd/install.c:72
|
||||
#: src/cmd/install.c:96
|
||||
msgid "Nothing to do (no packages to install)"
|
||||
msgstr "Nothing to do (no packages to install)"
|
||||
|
||||
#: src/cmd/install.c:81 src/cmd/install.c:83 src/cmd/remove.c:68
|
||||
#: src/cmd/remove.c:70 src/cmd/update.c:56 src/cmd/update.c:58
|
||||
#: src/cmd/install.c:105 src/cmd/install.c:107 src/cmd/remove.c:65
|
||||
#: src/cmd/remove.c:67 src/cmd/update.c:56 src/cmd/update.c:58
|
||||
msgid "Following "
|
||||
msgstr "Following "
|
||||
|
||||
#: src/cmd/install.c:89 src/cmd/remove.c:77
|
||||
#: src/cmd/install.c:113 src/cmd/remove.c:74
|
||||
msgid "Total of "
|
||||
msgstr "Total of "
|
||||
|
||||
#: src/cmd/install.c:92 src/cmd/update.c:65
|
||||
#: src/cmd/install.c:116 src/cmd/update.c:65
|
||||
#, 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:94 src/cmd/remove.c:78 src/cmd/update.c:67
|
||||
#: src/cmd/install.c:118 src/cmd/remove.c:75 src/cmd/update.c:67
|
||||
msgid "Continue?"
|
||||
msgstr "Continue?"
|
||||
|
||||
#: src/cmd/install.c:95 src/cmd/remove.c:79 src/cmd/update.c:68
|
||||
#: src/cmd/install.c:119 src/cmd/remove.c:76 src/cmd/update.c:68
|
||||
msgid "Operation cancelled"
|
||||
msgstr "Operation cancelled"
|
||||
|
||||
#: src/cmd/install.c:101 src/cmd/install.c:116 src/cmd/remove.c:86
|
||||
#: src/cmd/update.c:78 src/cmd/update.c:87 src/cmd/update.c:96
|
||||
#: src/cmd/install.c:135 src/cmd/install.c:139 src/cmd/install.c:154
|
||||
#: src/cmd/remove.c:83 src/cmd/update.c:78 src/cmd/update.c:87
|
||||
#: src/cmd/update.c:96
|
||||
msgid "("
|
||||
msgstr "("
|
||||
|
||||
#: src/cmd/install.c:107 src/cmd/update.c:83
|
||||
#: src/cmd/install.c:145 src/cmd/update.c:83
|
||||
msgid "Failed to download "
|
||||
msgstr "Failed to download "
|
||||
|
||||
#: src/cmd/install.c:122 src/cmd/update.c:101
|
||||
#: src/cmd/install.c:160 src/cmd/update.c:101
|
||||
msgid "Failed to install "
|
||||
msgstr "Failed to install "
|
||||
|
||||
#: src/cmd/install.c:128
|
||||
#: src/cmd/install.c:166
|
||||
msgid "Installed "
|
||||
msgstr "Installed "
|
||||
|
||||
#: src/cmd/install.c:128
|
||||
#: src/cmd/install.c:166
|
||||
msgid "Installed all of the "
|
||||
msgstr "Installed all of the "
|
||||
|
||||
@ -305,23 +315,23 @@ msgstr "Listing "
|
||||
msgid "Listing options for the remove command:"
|
||||
msgstr "Listing options for the remove command:"
|
||||
|
||||
#: src/cmd/remove.c:53
|
||||
#: src/cmd/remove.c:50
|
||||
msgid "Cannot remove "
|
||||
msgstr "Cannot remove "
|
||||
|
||||
#: src/cmd/remove.c:61
|
||||
#: src/cmd/remove.c:58
|
||||
msgid "Nothing to do (no packages to remove)"
|
||||
msgstr "Nothing to do (no packages to remove)"
|
||||
|
||||
#: src/cmd/remove.c:92 src/cmd/update.c:92
|
||||
#: src/cmd/remove.c:89 src/cmd/update.c:92
|
||||
msgid "Failed to remove "
|
||||
msgstr "Failed to remove "
|
||||
|
||||
#: src/cmd/remove.c:98
|
||||
#: src/cmd/remove.c:95
|
||||
msgid "Removed "
|
||||
msgstr "Removed "
|
||||
|
||||
#: src/cmd/remove.c:98
|
||||
#: src/cmd/remove.c:95
|
||||
msgid "Removed all of the "
|
||||
msgstr "Removed all of the "
|
||||
|
||||
|
@ -53,19 +53,19 @@ bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
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"))
|
||||
for(size_t i = 1; i < args->count; i++){
|
||||
if(NULL != args->list[i].name)
|
||||
continue;
|
||||
|
||||
if(NULL == name){
|
||||
name = args->list[i].value;
|
||||
if(NULL == name && NULL != (name = args->list[i].value))
|
||||
continue;
|
||||
}
|
||||
|
||||
else if(NULL != name && NULL != (name = args->list[i].value)){
|
||||
if(!args_get_bool(args, "grep"))
|
||||
error(_("Please specify only a single package name"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL == name){
|
||||
if(!args_get_bool(args, "grep"))
|
||||
|
@ -1,4 +1,9 @@
|
||||
#include <libmp/all.h>
|
||||
#include <libmp/ctx.h>
|
||||
#include <libmp/error.h>
|
||||
#include <libmp/package.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../util.h"
|
||||
@ -33,19 +38,37 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
return false;
|
||||
}
|
||||
|
||||
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_ctx_resolve_list_t *list = NULL;
|
||||
ssize_t current = 0, size = 0, save = 0;
|
||||
bool ret = false, r = false;
|
||||
char ssize[LONGSTR_MAX+3];
|
||||
lm_pkg_t *pkg = NULL;
|
||||
char *name = NULL;
|
||||
|
||||
for(int i = 0; i < args->count; i++){
|
||||
if(NULL != args->list[i].name)
|
||||
for(size_t i = 1; i < args->count; i++){
|
||||
if(NULL != args->list[i].name || NULL == (name = args->list[i].value))
|
||||
continue;
|
||||
|
||||
if(eq((name = args->list[i].value), "install"))
|
||||
continue;
|
||||
// if thiş 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);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(NULL == locals)
|
||||
locals = malloc(sizeof(lm_pkg_t));
|
||||
else
|
||||
locals = realloc(locals, sizeof(lm_pkg_t)*((++li)+1));
|
||||
|
||||
if(!lm_ctx_package_from(ctx, &locals[li], name)){
|
||||
error(_("Failed to load "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
pkg = &locals[li];
|
||||
goto resolve;
|
||||
}
|
||||
|
||||
// find the package
|
||||
if((pkg = lm_ctx_pool_find(ctx, name, NULL)) == NULL){
|
||||
@ -56,6 +79,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
goto end;
|
||||
}
|
||||
|
||||
resolve:
|
||||
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;
|
||||
@ -98,6 +122,20 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
|
||||
// download resolved packages
|
||||
while((pkg = lm_ctx_resolve_next(list)) != NULL){
|
||||
is_local = false;
|
||||
|
||||
for(size_t i = 0; i < (li+1) && NULL != locals; i++){
|
||||
if(lm_package_is_same(&locals[i], pkg)){
|
||||
is_local = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_local){
|
||||
info(_("("FG_BOLD"%d"FG_RESET"/"FG_BOLD"%d"FG_RESET") Skipping local package "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"), ++current, list->count, pkg->data.name, pkg->data.version);
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
@ -131,6 +169,11 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
|
||||
end:
|
||||
bar_free();
|
||||
|
||||
for(size_t i = 0; i < (li+1) && NULL != locals; i++)
|
||||
lm_ctx_package_from_free(&locals[li]);
|
||||
free(locals);
|
||||
|
||||
lm_ctx_resolve_free(list);
|
||||
return ret;
|
||||
}
|
||||
|
@ -29,11 +29,8 @@ bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args){
|
||||
lm_entry_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"))
|
||||
for(size_t i = 1; i < args->count; i++){
|
||||
if(NULL != args->list[i].name || NULL == (name = args->list[i].value))
|
||||
continue;
|
||||
|
||||
if(NULL == pkgs)
|
||||
|
12
src/util.c
12
src/util.c
@ -141,3 +141,15 @@ end:
|
||||
bool can_run_install(lm_ctx_t *ctx) {
|
||||
return eq(ctx->root, "/");
|
||||
}
|
||||
|
||||
bool endswith(char *str, char *suf) {
|
||||
if (NULL == str || NULL == suf)
|
||||
return false;
|
||||
|
||||
size_t strl = strlen(str), sufl = strlen(suf);
|
||||
|
||||
if (sufl > strl)
|
||||
return false;
|
||||
|
||||
return strncmp(str + strl - sufl, suf, sufl) == 0;
|
||||
}
|
||||
|
@ -13,3 +13,4 @@ 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);
|
||||
bool endswith(char *str, char *suf);
|
||||
|
Loading…
Reference in New Issue
Block a user