update: disabled root directory check for non-root commands
This commit is contained in:
parent
787d975c49
commit
4434b742c5
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2024-08-16 03:05+0300\n"
|
"POT-Creation-Date: 2024-08-16 03:44+0300\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -82,67 +82,71 @@ msgid "Received a segfault"
|
|||||||
msgstr "Received a segfault"
|
msgstr "Received a segfault"
|
||||||
|
|
||||||
#: src/main.c:102
|
#: src/main.c:102
|
||||||
|
msgid "Failed to lock, matt is already running"
|
||||||
|
msgstr "Failed to lock, matt is already running"
|
||||||
|
|
||||||
|
#: src/main.c:106
|
||||||
|
msgid "Failed to lock, are you root?"
|
||||||
|
msgstr "Failed to lock, are you root?"
|
||||||
|
|
||||||
|
#: src/main.c:130
|
||||||
msgid "Failed to access the root directory, are you running as root?"
|
msgid "Failed to access the root directory, are you running as root?"
|
||||||
msgstr "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:106
|
#: src/main.c:134
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
msgid "Failed to access the data directory ("
|
msgid "Failed to access the data directory ("
|
||||||
msgstr "Failed to access the configuration file: %s"
|
msgstr "Failed to access the configuration file: %s"
|
||||||
|
|
||||||
#: src/main.c:110
|
#: src/main.c:138
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
msgid "Failed to access the temp directory ("
|
msgid "Failed to access the temp directory ("
|
||||||
msgstr "Failed to open the editor: %s"
|
msgstr "Failed to open the editor: %s"
|
||||||
|
|
||||||
#: src/main.c:114
|
#: src/main.c:142
|
||||||
#, fuzzy, c-format
|
#, fuzzy, c-format
|
||||||
msgid "Failed to initialize libmp context: %s"
|
msgid "Failed to initialize libmp context: %s"
|
||||||
msgstr "Failed to install "
|
msgstr "Failed to install "
|
||||||
|
|
||||||
#: src/main.c:125
|
#: src/main.c:153
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
msgid "Failed to create the pools directory ("
|
msgid "Failed to create the pools directory ("
|
||||||
msgstr "Failed to open the editor: %s"
|
msgstr "Failed to open the editor: %s"
|
||||||
|
|
||||||
#: src/main.c:135
|
#: src/main.c:163
|
||||||
msgid "Failed to add pool "
|
msgid "Failed to add pool "
|
||||||
msgstr "Failed to add pool "
|
msgstr "Failed to add pool "
|
||||||
|
|
||||||
#: src/main.c:149
|
#: src/main.c:177
|
||||||
msgid "Failed to lock, matt is already running"
|
|
||||||
msgstr "Failed to lock, matt is already running"
|
|
||||||
|
|
||||||
#: src/main.c:153
|
|
||||||
msgid "Failed to lock, are you root?"
|
|
||||||
msgstr "Failed to lock, are you root?"
|
|
||||||
|
|
||||||
#: src/main.c:165
|
|
||||||
msgid "Command not found: "
|
msgid "Command not found: "
|
||||||
msgstr "Command not found: "
|
msgstr "Command not found: "
|
||||||
|
|
||||||
#: src/main.c:167
|
#: src/main.c:178
|
||||||
|
msgid "Displaying help information"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/main.c:181
|
||||||
#, fuzzy, c-format
|
#, fuzzy, c-format
|
||||||
msgid "MatterLinux package manager %s (libmp %s)"
|
msgid "MatterLinux package manager %s (libmp %s)"
|
||||||
msgstr "MatterLinux package manager (version %s)"
|
msgstr "MatterLinux package manager (version %s)"
|
||||||
|
|
||||||
#: src/main.c:168
|
#: src/main.c:182
|
||||||
msgid "Usage: "
|
msgid "Usage: "
|
||||||
msgstr "Usage: "
|
msgstr "Usage: "
|
||||||
|
|
||||||
#: src/main.c:170
|
#: src/main.c:184
|
||||||
msgid "Here is a list of available commands:"
|
msgid "Here is a list of available commands:"
|
||||||
msgstr "Here is a list of available commands:"
|
msgstr "Here is a list of available commands:"
|
||||||
|
|
||||||
#: src/main.c:176
|
#: src/main.c:190
|
||||||
msgid "To list different options, use commands with "
|
msgid "To list different options, use commands with "
|
||||||
msgstr "To list different options, use commands with "
|
msgstr "To list different options, use commands with "
|
||||||
|
|
||||||
#: src/main.c:177
|
#: src/main.c:191
|
||||||
msgid "Here is a list of available global options:"
|
msgid "Here is a list of available global options:"
|
||||||
msgstr "Here is a list of available global options:"
|
msgstr "Here is a list of available global options:"
|
||||||
|
|
||||||
#: src/main.c:180 src/main.c:181 src/cmd/info.c:54 src/cmd/info.c:55
|
#: 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/cmd/info.c:56 src/cmd/install.c:34 src/cmd/install.c:35
|
||||||
#: src/cmd/install.c:36 src/cmd/install.c:37 src/cmd/install.c:38
|
#: 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/list.c:24 src/cmd/list.c:25 src/cmd/remove.c:28 src/cmd/remove.c:29
|
||||||
@ -151,7 +155,7 @@ msgstr "Here is a list of available global options:"
|
|||||||
msgid " "
|
msgid " "
|
||||||
msgstr " "
|
msgstr " "
|
||||||
|
|
||||||
#: src/main.c:183
|
#: src/main.c:197
|
||||||
msgid ""
|
msgid ""
|
||||||
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
|
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -10,6 +10,7 @@ typedef bool (*cmd_func_t)(lm_ctx_t *ctx, config_t *config, args_t *args);
|
|||||||
typedef struct cmd {
|
typedef struct cmd {
|
||||||
char *name;
|
char *name;
|
||||||
char *desc;
|
char *desc;
|
||||||
|
bool root;
|
||||||
cmd_func_t func;
|
cmd_func_t func;
|
||||||
} cmd_t;
|
} cmd_t;
|
||||||
|
|
||||||
|
74
src/main.c
74
src/main.c
@ -60,19 +60,20 @@ int main(int argc, char *argv[], char *envp[]) {
|
|||||||
textdomain("matt");
|
textdomain("matt");
|
||||||
|
|
||||||
cmd_t commands[] = {
|
cmd_t commands[] = {
|
||||||
{.name = "info", .desc = "show information about a single package", .func = cmd_info },
|
{.name = "info", .desc = "show information about a single package", .root = false, .func = cmd_info },
|
||||||
{.name = "list", .desc = "list all the installed packages", .func = cmd_list },
|
{.name = "list", .desc = "list all the installed packages", .root = false, .func = cmd_list },
|
||||||
{.name = "sync", .desc = "update the pool info and package lists", .func = cmd_sync },
|
{.name = "sync", .desc = "update the pool info and package lists", .root = true, .func = cmd_sync },
|
||||||
{.name = "install", .desc = "install package(s) from remote pools", .func = cmd_install},
|
{.name = "install", .desc = "install package(s) from remote pools", .root = true, .func = cmd_install},
|
||||||
{.name = "remove", .desc = "remove installed package(s)", .func = cmd_remove },
|
{.name = "remove", .desc = "remove installed package(s)", .root = true, .func = cmd_remove },
|
||||||
{.name = "update", .desc = "update installed package(s)", .func = cmd_update },
|
{.name = "update", .desc = "update installed package(s)", .root = true, .func = cmd_update },
|
||||||
};
|
};
|
||||||
|
|
||||||
char *full_datadir = NULL, *full_tmpdir = NULL, *full_pooldir = NULL;
|
char *full_datadir = NULL, *full_tmpdir = NULL, *full_pooldir = NULL;
|
||||||
char *config_file = NULL, *root_dir = NULL;
|
bool ret = false, r = false, use_root = false;
|
||||||
bool ret = false, r = false;
|
char *config_file = NULL, *root_dir = NULL;
|
||||||
args_t *args = NULL;
|
cmd_func_t cmd = NULL;
|
||||||
config_t config;
|
args_t *args = NULL;
|
||||||
|
config_t config;
|
||||||
|
|
||||||
set_env(envp);
|
set_env(envp);
|
||||||
lm_ctx_init(&ctx);
|
lm_ctx_init(&ctx);
|
||||||
@ -87,6 +88,33 @@ int main(int argc, char *argv[], char *envp[]) {
|
|||||||
if (!config_load(&ctx, &config, config_file))
|
if (!config_load(&ctx, &config, config_file))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
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)
|
if (args->count <= 0 || args->list[0].name != NULL)
|
||||||
goto help;
|
goto help;
|
||||||
|
|
||||||
@ -96,7 +124,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
|||||||
full_datadir = join_alloc(root_dir, config.datadir);
|
full_datadir = join_alloc(root_dir, config.datadir);
|
||||||
full_tmpdir = join_alloc(root_dir, config.tmpdir);
|
full_tmpdir = join_alloc(root_dir, config.tmpdir);
|
||||||
|
|
||||||
if (!lm_ctx_new(&ctx, root_dir, full_tmpdir, full_datadir)) {
|
if (!lm_ctx_new(&ctx, use_root ? root_dir : NULL, full_tmpdir, full_datadir)) {
|
||||||
switch (lm_error()) {
|
switch (lm_error()) {
|
||||||
case LM_ERR_CtxRootFail:
|
case LM_ERR_CtxRootFail:
|
||||||
error(_("Failed to access the root directory, are you running as root?"));
|
error(_("Failed to access the root directory, are you running as root?"));
|
||||||
@ -140,29 +168,15 @@ int main(int argc, char *argv[], char *envp[]) {
|
|||||||
pool = pool->next;
|
pool = pool->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(commands) / sizeof(cmd_t); i++) {
|
if (NULL != cmd) {
|
||||||
if (!eq(commands[i].name, args->list[0].value))
|
ret = cmd(&ctx, &config, args);
|
||||||
continue;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = commands[i].func(&ctx, &config, args);
|
|
||||||
unlock(&ctx);
|
unlock(&ctx);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
error(_("Command not found: " FG_BOLD "%s"), args->list[0].value);
|
error(_("Command not found: " FG_BOLD "%s"), args->list[0].value);
|
||||||
|
info(_("Displaying help information"));
|
||||||
|
|
||||||
help:
|
help:
|
||||||
info(_("MatterLinux package manager %s (libmp %s)"), VERSION, LM_VERSION);
|
info(_("MatterLinux package manager %s (libmp %s)"), VERSION, LM_VERSION);
|
||||||
info(_("Usage: " FG_BOLD "%s [command] <options> <arguments>"), argv[0]);
|
info(_("Usage: " FG_BOLD "%s [command] <options> <arguments>"), argv[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user