update: make things work with libmp update

This commit is contained in:
ngn 2024-08-04 15:55:02 +03:00
parent dc4bfd7e7d
commit 049642d06b
12 changed files with 198 additions and 115 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-01 01:59+0300\n"
"POT-Creation-Date: 2024-08-04 15:54+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"
@ -17,29 +17,29 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/config.c:70
#: src/config.c:71
#, c-format
msgid "Unknown configuration option: %s/%s"
msgstr "Unknown configuration option: %s/%s"
#: src/config.c:78
#, c-format
msgid "Failed to access the configuration file: %s"
#: src/config.c:79
#, fuzzy
msgid "Failed to access the configuration file: "
msgstr "Failed to access the configuration file: %s"
#: src/config.c:83
#: src/config.c:84
msgid "Failed to parse the configuration"
msgstr "Failed to parse the configuration"
#: src/config.c:88
#: src/config.c:89
msgid "Please specify \"tmpdir\" in the configuration"
msgstr "Please specify \"tmpdir\" in the configuration"
#: src/config.c:93
#: src/config.c:94
msgid "Please specify \"datadir\" in the configuration"
msgstr "Please specify \"datadir\" in the configuration"
#: src/config.c:100
#: src/config.c:101
#, c-format
msgid "URL not specified for the pool: %s"
msgstr "URL not specified for the pool: %s"
@ -73,288 +73,305 @@ msgstr "Please answer with y/n"
msgid "Received a segfault"
msgstr "Received a segfault"
#: src/main.c:93
#: src/main.c:97
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:95
#, c-format
msgid "Bad root directory (%s): %s"
msgstr "Bad root directory (%s): %s"
#: src/main.c:101
#, fuzzy
msgid "Failed to access the data directory ("
msgstr "Failed to access the configuration file: %s"
#: src/main.c:103
#, c-format
msgid "Bad datadir (%s): %s"
msgstr "Bad datadir (%s): %s"
#: src/main.c:105
#, fuzzy
msgid "Failed to access the temp directory ("
msgstr "Failed to open the editor: %s"
#: src/main.c:108
#, c-format
msgid "Bad tmpdir (%s): %s"
msgstr "Bad tmpdir (%s): %s"
#: src/main.c:109
#, fuzzy, c-format
msgid "Failed to initialize libmp context: %s"
msgstr "Failed to install "
#: src/main.c:115
#: src/main.c:120
#, fuzzy
msgid "Failed to create the pools directory ("
msgstr "Failed to open the editor: %s"
#: src/main.c:130
msgid "Failed to add pool "
msgstr "Failed to add pool "
#: src/main.c:127
#: src/main.c:144
msgid "Failed to lock, matt is already running"
msgstr "Failed to lock, matt is already running"
#: src/main.c:131
#: src/main.c:148
msgid "Failed to lock, are you root?"
msgstr "Failed to lock, are you root?"
#: src/main.c:142
#: src/main.c:159
msgid "Command not found: "
msgstr "Command not found: "
#: src/main.c:144
#: src/main.c:161
#, c-format
msgid "MatterLinux package manager (version %s)"
msgstr "MatterLinux package manager (version %s)"
#: src/main.c:145
#: src/main.c:162
msgid "Usage: "
msgstr "Usage: "
#: src/main.c:147
#: src/main.c:164
msgid "Here is a list of available commands:"
msgstr "Here is a list of available commands:"
#: src/main.c:153
#: src/main.c:170
msgid "To list different options, use commands with "
msgstr "To list different options, use commands with "
#: src/main.c:154
#: src/main.c:171
msgid "Here is a list of available global options:"
msgstr "Here is a list of available global options:"
#: src/main.c:157 src/main.c:158 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:29
#: 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/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
msgid " "
msgstr " "
#: src/main.c:160
#: src/main.c:177
msgid ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
msgstr ""
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
#: src/util.c:83
#: src/util.c:120
msgid "No available editor to open "
msgstr "No available editor to open "
#: src/util.c:90
#: src/util.c:127
#, c-format
msgid "Failed to run the editor: %s"
msgstr "Failed to run the editor: %s"
#: src/util.c:95
#: src/util.c:132
#, c-format
msgid "Failed to open the editor: %s"
msgstr "Failed to open the editor: %s"
#: src/cmd/info.c:18 src/cmd/info.c:28 src/cmd/install.c:59 src/cmd/remove.c:45
#: src/cmd/info.c:19 src/cmd/info.c:29 src/cmd/install.c:60 src/cmd/remove.c:46
msgid "Package "
msgstr "Package "
#: src/cmd/info.c:41 src/cmd/list.c:12
#: src/cmd/info.c:42 src/cmd/list.c:13
msgid "Listing options for the list command:"
msgstr "Listing options for the list command:"
#: src/cmd/info.c:65
#: src/cmd/info.c:66
msgid "Please specify only a single package name"
msgstr "Please specify only a single package name"
#: src/cmd/info.c:71
#: src/cmd/info.c:72
msgid "Please specify a single package"
msgstr "Please specify a single package"
#: src/cmd/info.c:86
#: src/cmd/info.c:87
msgid "Failed to get the changes file for "
msgstr "Failed to get the changes file for "
#: src/cmd/info.c:92
#: src/cmd/info.c:93
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:99
#: src/cmd/info.c:100
msgid "Failed to get the depends list for "
msgstr "Failed to get the depends list for "
#: src/cmd/info.c:126
#: src/cmd/info.c:127
#, c-format
msgid "Name "
msgstr "Name "
#: src/cmd/info.c:127
#: src/cmd/info.c:128
#, c-format
msgid "Version "
msgstr "Version "
#: src/cmd/info.c:128
#: src/cmd/info.c:129
#, c-format
msgid "Desc "
msgstr "Desc "
#: src/cmd/info.c:129
#: src/cmd/info.c:130
#, c-format
msgid "Size "
msgstr "Size "
#: src/cmd/info.c:132
#: src/cmd/info.c:133
#, c-format
msgid "Depends "
msgstr "Depends "
#: src/cmd/info.c:135
#: src/cmd/info.c:136
#, c-format
msgid "Changes "
msgstr "Changes "
#: src/cmd/info.c:139 src/cmd/info.c:140
#: src/cmd/info.c:140 src/cmd/info.c:141
#, c-format
msgid "Installed "
msgstr "Installed "
#: src/cmd/info.c:142 src/cmd/info.c:143
#: src/cmd/info.c:143 src/cmd/info.c:144
#, c-format
msgid "Up-to-date "
msgstr "Up-to-date "
#: src/cmd/install.c:24
#: src/cmd/install.c:25
msgid "Listing options for the install command:"
msgstr "Listing options for the install command:"
#: src/cmd/install.c:31 src/cmd/update.c:34
#: src/cmd/install.c:32 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:51 src/cmd/remove.c:47
#: src/cmd/install.c:52 src/cmd/remove.c:48
msgid "Failed to find "
msgstr "Failed to find "
#: src/cmd/install.c:65
#: src/cmd/install.c:66
msgid "Failed to resolve "
msgstr "Failed to resolve "
#: src/cmd/install.c:71
#: src/cmd/install.c:72
msgid "Nothing to do (no packages to install)"
msgstr "Nothing to do (no packages to install)"
#: src/cmd/install.c:80 src/cmd/install.c:82 src/cmd/remove.c:67
#: src/cmd/remove.c:69 src/cmd/update.c:55 src/cmd/update.c:57
#: 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
msgid "Following "
msgstr "Following "
#: src/cmd/install.c:88 src/cmd/remove.c:76
#: src/cmd/install.c:89 src/cmd/remove.c:77
msgid "Total of "
msgstr "Total of "
#: src/cmd/install.c:91 src/cmd/update.c:64
#: src/cmd/install.c:92 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:93 src/cmd/remove.c:77 src/cmd/update.c:66
#: src/cmd/install.c:94 src/cmd/remove.c:78 src/cmd/update.c:67
msgid "Continue?"
msgstr "Continue?"
#: src/cmd/install.c:94 src/cmd/remove.c:78 src/cmd/update.c:67
#: src/cmd/install.c:95 src/cmd/remove.c:79 src/cmd/update.c:68
msgid "Operation cancelled"
msgstr "Operation cancelled"
#: 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
#: 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
msgid "("
msgstr "("
#: src/cmd/install.c:106 src/cmd/update.c:82
#: src/cmd/install.c:107 src/cmd/update.c:83
msgid "Failed to download "
msgstr "Failed to download "
#: src/cmd/install.c:121 src/cmd/update.c:100
#: src/cmd/install.c:122 src/cmd/update.c:101
msgid "Failed to install "
msgstr "Failed to install "
#: src/cmd/install.c:127
#: src/cmd/install.c:128
msgid "Installed "
msgstr "Installed "
#: src/cmd/install.c:127
#: src/cmd/install.c:128
msgid "Installed all of the "
msgstr "Installed all of the "
#: src/cmd/list.c:27
#: src/cmd/list.c:28
msgid "There no installed packages"
msgstr "There no installed packages"
#: src/cmd/list.c:32
#: src/cmd/list.c:33
msgid "Listing "
msgstr "Listing "
#: src/cmd/remove.c:19
#: src/cmd/remove.c:20
msgid "Listing options for the remove command:"
msgstr "Listing options for the remove command:"
#: src/cmd/remove.c:52
#: src/cmd/remove.c:53
msgid "Cannot remove "
msgstr "Cannot remove "
#: src/cmd/remove.c:60
#: src/cmd/remove.c:61
msgid "Nothing to do (no packages to remove)"
msgstr "Nothing to do (no packages to remove)"
#: src/cmd/remove.c:91 src/cmd/update.c:91
#: src/cmd/remove.c:92 src/cmd/update.c:92
msgid "Failed to remove "
msgstr "Failed to remove "
#: src/cmd/remove.c:97
#: src/cmd/remove.c:98
msgid "Removed "
msgstr "Removed "
#: src/cmd/remove.c:97
#: src/cmd/remove.c:98
msgid "Removed all of the "
msgstr "Removed all of the "
#: src/cmd/sync.c:19
#: src/cmd/sync.c:20
msgid "Failed to sync "
msgstr "Failed to sync "
#: src/cmd/sync.c:28 src/cmd/sync.c:58
#: src/cmd/sync.c:29 src/cmd/sync.c:59
msgid "Synced "
msgstr "Synced "
#: src/cmd/sync.c:34
#: src/cmd/sync.c:35
#, c-format
msgid "Failed to sync %s: %s"
msgstr "Failed to sync %s: %s"
#: src/cmd/sync.c:46
#: src/cmd/sync.c:47
msgid "There are no pools specified in the configuration"
msgstr "There are no pools specified in the configuration"
#: src/cmd/sync.c:54
#: src/cmd/sync.c:55
#, c-format
msgid "Failed to sync pools: %s"
msgstr "Failed to sync pools: %s"
#: src/cmd/update.c:28
#: src/cmd/update.c:29
msgid "Listing options for the update command:"
msgstr "Listing options for the update command:"
#: src/cmd/update.c:45
#: src/cmd/update.c:46
#, c-format
msgid "Failed to get the package update list: %s"
msgstr "Failed to get the package update list: %s"
#: src/cmd/update.c:50
#: src/cmd/update.c:51
msgid "All packages are up-to-date"
msgstr "All packages are up-to-date"
#: src/cmd/update.c:73
#: src/cmd/update.c:74
msgid "Failed to update "
msgstr "Failed to update "
#, 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

@ -7,6 +7,7 @@
#include <stdlib.h>
#include "../util.h"
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include "../util.h"
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -1,6 +1,7 @@
#include <libmp/all.h>
#include <stdio.h>
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include "../util.h"
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -1,6 +1,7 @@
#include <libmp/all.h>
#include <stdio.h>
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include "../util.h"
#include "../intl.h"
#include "../cmd.h"
#include "../log.h"

View File

@ -8,6 +8,7 @@
#include "config.h"
#include "intl.h"
#include "log.h"
#include "util.h"
bool config_set(config_t *config, char *key, char *value) {
if (eq(key, "tmpdir"))
@ -74,8 +75,8 @@ unknown:
bool config_load(lm_ctx_t *ctx, config_t *config, char *file) {
bzero(config, sizeof(config_t));
if (!exists(file) || !can_read(file)) {
error(_("Failed to access the configuration file: %s"), file);
if (access(file, R_OK) != 0) {
error(_("Failed to access the configuration file: " FG_BOLD "%s"), file);
return false;
}

View File

@ -1,9 +1,10 @@
#include "lock.h"
#include <fcntl.h>
#include <libmp/util.h>
#include <string.h>
#include <unistd.h>
#include "lock.h"
#include "util.h"
lock_st lock(lm_ctx_t *ctx) {
if (NULL == ctx->data)
return LOCK_ERROR;
@ -11,7 +12,7 @@ lock_st lock(lm_ctx_t *ctx) {
char lock_file[strlen(ctx->data) + 10];
join(lock_file, ctx->data, "lock");
if (exists(lock_file))
if (access(lock_file, F_OK) == 0)
return ALREADY_LOCKED;
if (creat(lock_file, 0600) == -1)
return LOCK_ERROR;

View File

@ -22,14 +22,14 @@
// clang-format on
#include <errno.h>
#include <libmp/all.h>
#include <libmp/ctx.h>
#include <libmp/error.h>
#include <libmp/util.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "args.h"
#include "cmd.h"
@ -66,10 +66,10 @@ int main(int argc, char *argv[], char *envp[]) {
{.name = "update", .desc = "update installed package(s)", .func = cmd_update },
};
char *full_datadir = NULL, *full_tmpdir = NULL, *full_pooldir = NULL;
char *config_file = NULL, *root_dir = NULL;
char *full_datadir = NULL, *full_tmpdir = NULL;
bool ret = false, r = false;
args_t *args = NULL;
bool ret = false;
config_t config;
set_env(envp);
@ -88,33 +88,50 @@ int main(int argc, char *argv[], char *envp[]) {
if ((root_dir = args_get_string(args, "root")) == NULL)
root_dir = "/";
if (!lm_ctx_set_root(&ctx, root_dir)) {
if (LM_ERR_CtxRootNoWrite == lm_error())
error(_("Failed to access the root directory, are you running as root?"));
else
error(_("Bad root directory (%s): %s"), root_dir, lm_strerror());
goto end;
}
full_datadir = join_alloc(root_dir, config.datadir);
full_tmpdir = join_alloc(root_dir, config.tmpdir);
if (!lm_ctx_set_data(&ctx, full_datadir)) {
error(_("Bad datadir (%s): %s"), full_datadir, lm_strerror());
goto end;
if (!lm_ctx_new(&ctx, root_dir, full_tmpdir, full_datadir)) {
switch (lm_error()) {
case LM_ERR_CtxRootFail:
error(_("Failed to access the root directory, are you running as root?"));
break;
case LM_ERR_CtxDataFail:
error(_("Failed to access the data directory (" FG_BOLD "%s" FG_RESET ")"), full_datadir);
break;
case LM_ERR_CtxTempFail:
error(_("Failed to access the temp directory (" FG_BOLD "%s" FG_RESET ")"), full_tmpdir);
break;
default:
error(_("Failed to initialize libmp context: %s"), lm_strerror());
break;
}
if (!lm_ctx_set_temp(&ctx, full_tmpdir)) {
error(_("Bad tmpdir (%s): %s"), full_tmpdir, lm_strerror());
goto end;
}
pool_config_t *pool = config.pools;
full_pooldir = join_alloc(full_datadir, "pools");
if (mkdir(full_pooldir, 0755) < 0 && errno != EEXIST) {
error(_("Failed to create the pools directory (" FG_BOLD "%s" FG_RESET "): %s"), pool->name, strerror(errno));
goto end;
}
while (NULL != pool) {
if (!lm_ctx_pool_add(&ctx, pool->name, pool->url)) {
char *pd = join_alloc(full_pooldir, pool->name);
r = lm_ctx_pool_add(&ctx, pool->name, pool->url, pd);
if (!r) {
error(_("Failed to add pool " FG_BOLD "%s" FG_RESET " to the list: %s"), pool->name, lm_strerror());
goto end;
}
free(pd);
pool = pool->next;
}
@ -165,6 +182,7 @@ help:
end:
unlock(&ctx);
free(full_pooldir);
free(full_datadir);
free(full_tmpdir);

View File

@ -1,12 +1,13 @@
#include <errno.h>
#include <libmp/util.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <wait.h>
#include "intl.h"
#include "log.h"
#include "util.h"
@ -16,6 +17,16 @@ void set_env(char **envp) {
env = envp;
}
bool eq(char *s1, char *s2) {
if (NULL == s1 || NULL == s2)
return false;
if (strlen(s1) != strlen(s2))
return false;
return strcmp(s1, s2) == 0;
}
bool startswith(char *str, char *sub) {
size_t strl = strlen(str);
size_t subl = strlen(sub);
@ -26,6 +37,32 @@ bool startswith(char *str, char *sub) {
return strncmp(sub, str, subl) == 0;
}
int join(char *res, const char *base, const char *pth) {
int blen = strlen(base);
if ((base[blen - 1] == '/' && pth[0] != '/') || (base[blen - 1] != '/' && pth[0] == '/')) {
return sprintf(res, "%s%s", base, pth);
} else if (base[blen - 1] != '/' && pth[0] != '/') {
return sprintf(res, "%s/%s", base, pth);
} else if (base[blen - 1] == '/' && pth[0] == '/') {
char *basedup = strdup(base);
basedup[blen - 1] = '\0';
return sprintf(res, "%s%s", basedup, pth);
}
return -1;
}
char *join_alloc(char *p1, char *p2) {
char *fp = malloc(strlen(p1) + strlen(p2) + 5);
if (!join(fp, p1, p2)) {
free(fp);
fp = NULL;
}
return fp;
}
void size_to_human(char *buf, long size) {
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
char length = sizeof(suffix) / sizeof(suffix[0]);
@ -58,7 +95,7 @@ char *exists_in_path(char *file) {
char fp[strlen(part) + filesz + 1];
join(fp, part, file);
if (exists(fp))
if (access(fp, X_OK) == 0)
return strdup(fp);
} while ((part = strtok_r(NULL, ":", &save)) != NULL);

View File

@ -5,6 +5,9 @@
#define LONGSTR_MAX 30
void set_env(char **envp);
bool eq(char *s1, char *s2);
int join(char *res, const char *base, const char *pth);
char *join_alloc(char *p1, char *p2);
bool startswith(char *str, char *sub);
void size_to_human(char *buf, long size);
char *exists_in_path(char *file);