fix: temp directory changes for non-root commands
This commit is contained in:
parent
3edf678b30
commit
6b1f46166f
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-08-16 03:54+0300\n"
|
||||
"POT-Creation-Date: 2024-08-16 06:48+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"
|
||||
@ -76,98 +76,98 @@ 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:63
|
||||
#: src/main.c:64
|
||||
#, fuzzy
|
||||
msgid "show information about a single package"
|
||||
msgstr "show information about a single package"
|
||||
|
||||
#: src/main.c:64
|
||||
#: src/main.c:65
|
||||
msgid "list all the installed packages"
|
||||
msgstr "list all the installed packages"
|
||||
|
||||
#: src/main.c:65
|
||||
#: src/main.c:66
|
||||
msgid "update the pool info and package lists"
|
||||
msgstr "update the pool info and package lists"
|
||||
|
||||
#: src/main.c:66
|
||||
#: src/main.c:67
|
||||
msgid "install package(s) from remote pools"
|
||||
msgstr "install package(s) from remote pools"
|
||||
|
||||
#: src/main.c:67
|
||||
#: src/main.c:68
|
||||
msgid "remove installed package(s)"
|
||||
msgstr "remove installed package(s)"
|
||||
|
||||
#: src/main.c:68
|
||||
#: src/main.c:69
|
||||
msgid "update installed package(s)"
|
||||
msgstr "update installed package(s)"
|
||||
|
||||
#: 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
|
||||
#: src/main.c:118
|
||||
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
|
||||
#: src/main.c:122
|
||||
msgid "Failed to access the data directory ("
|
||||
msgstr "Failed to access the data directory ("
|
||||
|
||||
#: src/main.c:138
|
||||
#: src/main.c:126
|
||||
msgid "Failed to access the temp directory ("
|
||||
msgstr "Failed to access the temp directory ("
|
||||
|
||||
#: src/main.c:142
|
||||
#: src/main.c:130
|
||||
#, c-format
|
||||
msgid "Failed to initialize libmp context: %s"
|
||||
msgstr "Failed to initialize libmp context: %s"
|
||||
|
||||
#: src/main.c:153
|
||||
#: src/main.c:141
|
||||
msgid "Failed to create the pools directory ("
|
||||
msgstr "Failed to create the pools directory ("
|
||||
|
||||
#: src/main.c:163
|
||||
#: src/main.c:151
|
||||
msgid "Failed to add pool "
|
||||
msgstr "Failed to add pool "
|
||||
|
||||
#: src/main.c:177
|
||||
#: src/main.c:165
|
||||
msgid "Failed to lock, matt is already running"
|
||||
msgstr "Failed to lock, matt is already running"
|
||||
|
||||
#: src/main.c:169
|
||||
msgid "Failed to lock, are you root?"
|
||||
msgstr "Failed to lock, are you root?"
|
||||
|
||||
#: src/main.c:182
|
||||
msgid "Command not found: "
|
||||
msgstr "Command not found: "
|
||||
|
||||
#: src/main.c:178
|
||||
#: src/main.c:183
|
||||
msgid "Displaying help information"
|
||||
msgstr "Displaying help information"
|
||||
|
||||
#: src/main.c:181
|
||||
#: src/main.c:186
|
||||
#, c-format
|
||||
msgid "MatterLinux package manager %s (libmp %s)"
|
||||
msgstr "MatterLinux package manager %s (libmp %s)"
|
||||
|
||||
#: src/main.c:182
|
||||
#: src/main.c:187
|
||||
msgid "Usage: "
|
||||
msgstr "Usage: "
|
||||
|
||||
#: src/main.c:184
|
||||
#: src/main.c:189
|
||||
msgid "Here is a list of available commands:"
|
||||
msgstr "Here is a list of available commands:"
|
||||
|
||||
#: src/main.c:190
|
||||
#: src/main.c:195
|
||||
msgid "To list different options, use commands with "
|
||||
msgstr "To list different options, use commands with "
|
||||
|
||||
#: src/main.c:191
|
||||
#: src/main.c:196
|
||||
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/main.c:199 src/main.c:200 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/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
|
||||
@ -176,7 +176,7 @@ msgstr "Here is a list of available global options:"
|
||||
msgid " "
|
||||
msgstr " "
|
||||
|
||||
#: src/main.c:197
|
||||
#: src/main.c:202
|
||||
msgid ""
|
||||
"Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information"
|
||||
msgstr ""
|
||||
|
53
src/main.c
53
src/main.c
@ -30,6 +30,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "args.h"
|
||||
#include "cmd.h"
|
||||
@ -69,8 +70,8 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
};
|
||||
|
||||
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 +89,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;
|
||||
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 +157,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;
|
||||
|
Loading…
Reference in New Issue
Block a user