update: finish up the pull command

This commit is contained in:
ngn 2024-05-02 23:20:33 +03:00
parent d7e347175f
commit 9e8f57c175
10 changed files with 98 additions and 41 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-02 23:10+0300\n"
"POT-Creation-Date: 2024-05-02 23:20+0300\n"
"PO-Revision-Date: 2024-05-01 13:34+0300\n"
"Last-Translator: <ngn@ngn.tf>\n"
"Language-Team: Turkish <gnome-turk@gnome.org>\n"
@ -50,7 +50,7 @@ msgstr ""
msgid "Configuration details:\n"
msgstr ""
#: src/config.c:178
#: src/config.c:178 src/target.c:119
msgid "Name"
msgstr ""
@ -82,11 +82,11 @@ msgstr ""
msgid "Failed to load the configuration file (mc.cfg):"
msgstr ""
#: src/gen.c:42
#: src/gen.c:42 src/pull.c:109
msgid "Copying all the targets"
msgstr ""
#: src/gen.c:48
#: src/gen.c:48 src/pull.c:121
msgid "Failed to copy the target:"
msgstr ""
@ -184,43 +184,59 @@ msgstr ""
msgid "Do you want to continue?"
msgstr ""
#: src/pull.c:88
#: src/pull.c:91
msgid "Checking all the targets"
msgstr ""
#: src/pull.c:92
#: src/pull.c:97
#, c-format
msgid "Failed to access the source for the target \"%s\""
msgstr ""
#: src/pull.c:98
msgid "All the targets are OK"
#: src/pull.c:106
msgid "All the target checks were successful"
msgstr ""
#: src/target.c:13
#: src/pull.c:114
msgid "Install the target?"
msgstr ""
#: src/pull.c:115
msgid "Skipping target"
msgstr ""
#: src/target.c:15
msgid "Configuration target is missing a name"
msgstr ""
#: src/target.c:18
#: src/target.c:20
#, c-format
msgid "Configuration target \"%s\" does not have \"dst\" field"
msgstr ""
#: src/target.c:23
#: src/target.c:25
#, c-format
msgid "Configuration target \"%s\" does not have \"src\" field"
msgstr ""
#: src/target.c:38
#: src/target.c:40
#, c-format
msgid "Failed to open the directory: %s"
msgstr ""
#: src/target.c:79
#: src/target.c:81
#, c-format
msgid "Source directory \"%s\" does not exist"
msgstr ""
#: src/target.c:118
msgid "Target details:\n"
msgstr ""
#: src/target.c:120
msgid "Description"
msgstr ""
#: src/util.c:115 src/util.c:126
#, c-format
msgid "Failed to create directory: %s"

View File

@ -2,11 +2,11 @@
#include <stdlib.h>
#include <string.h>
#include "paths.h"
#include "config.h"
#include "error.h"
#include "intl.h"
#include "log.h"
#include "paths.h"
#include "util.h"
bool config_contains_target(config_t *config, char *name) {
@ -49,7 +49,7 @@ bool config_add_target(config_t *config, char *name) {
target_t *new = malloc(sizeof(target_t));
target_init(new);
new->name = name;
config->t_len++;
if (NULL == config->t_first || NULL == config->t_last) {
@ -100,7 +100,7 @@ int config_handler(void *data, const char *section, const char *key, const char
config->t_last->desc = strdup(value);
return 1;
} else if (MATCHKEY("dst")) {
int len = strlen(value)+strlen(mc_root)+2;
int len = strlen(value) + strlen(mc_root) + 2;
config->t_last->dst = malloc(len);
join(config->t_last->dst, mc_root, value);
return 1;

View File

@ -7,7 +7,7 @@
typedef struct config {
target_t *t_first;
target_t *t_last;
size_t t_len;
size_t t_len;
char *name;
char *author;

View File

@ -7,11 +7,11 @@ enum ErrorCodes {
ConfigParseFail = 952,
ConfigMultiple = 951,
TargetSrcFail = 950,
TargetSrcFail = 950,
OpendirFail = 948,
MkdirFail = 945,
OpenFail = 944,
MkdirFail = 945,
OpenFail = 944,
};
extern int errno;

View File

@ -36,20 +36,20 @@ bool gen_cmd() {
success(_("Loaded repository configuration"));
config_print(&cfg);
target_t *cur = cfg.t_first;
int counter = 0;
target_t *cur = cfg.t_first;
int counter = 0;
info(_("Copying all the targets"));
bar_init();
while (cur && ++counter > 0) {
if(!target_copy(cur, true)){
if (!target_copy(cur, true)) {
bar_free();
error(_("Failed to copy the target:"));
details(errch);
goto END;
}
bar(counter, cfg.t_len);
cur = cur->next;
}

View File

@ -85,17 +85,48 @@ COPY:
if (!yesno(_("Do you want to continue?")))
goto END;
target_t *cur = repo_cfg.t_first;
int counter = 0;
info(_("Checking all the targets"));
target_t *cur = repo_cfg.t_first;
while (NULL != cur) {
bar_init();
while (NULL != cur && ++counter > 0) {
if (!exists(cur->src)) {
bar_free();
error(_("Failed to access the source for the target \"%s\""), cur->name);
goto END;
}
cur = cur->next;
bar(counter, repo_cfg.t_len);
}
bar_free();
success(_("All the target checks were successful"));
cur = repo_cfg.t_first;
info(_("Copying all the targets"));
while (cur && ++counter > 0) {
target_print(cur);
if (!yesno(_("Install the target?"))) {
info(_("Skipping target"));
cur = cur->next;
continue;
}
if (!target_copy(cur, false)) {
error(_("Failed to copy the target:"));
details(errch);
goto END;
}
cur = cur->next;
}
success(_("All the targets are OK"));
ret = true;
END:
if (repo_cfg.name != NULL)

View File

@ -1,10 +1,12 @@
#include "target.h"
#include "error.h"
#include "intl.h"
#include "log.h"
#include "util.h"
#include <libgen.h>
#include <dirent.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -44,8 +46,8 @@ bool target_copy_dir(char *src, char *dst) {
size_t dst_len = strlen(dst);
while ((ent = readdir(dir)) != NULL) {
if(eq(ent->d_name, ".") || eq(ent->d_name, ".."))
continue;
if (eq(ent->d_name, ".") || eq(ent->d_name, ".."))
continue;
size_t len = strlen(ent->d_name);
char src_fp[src_len + len + 2], dst_fp[dst_len + len + 2];
@ -68,7 +70,7 @@ bool target_copy_dir(char *src, char *dst) {
bool target_copy(target_t *t, bool fromdst) {
char *src = t->src, *dst = t->dst;
bool ret = false;
bool ret = false;
if (fromdst) {
src = t->dst;
@ -84,10 +86,10 @@ bool target_copy(target_t *t, bool fromdst) {
if (is_dir(src))
return target_copy_dir(src, dst);
char *dstcp = strdup(dst);
char *dstcp = strdup(dst);
char *dstdir = dirname(dst);
if(!mksubdirsp(dstdir, 0755))
if (!mksubdirsp(dstdir, 0755))
return ret;
ret = copyfile(src, dstcp);
@ -111,3 +113,10 @@ void target_free(target_t *t) {
free(t->src);
clist_free(&t->requires);
}
void target_print(target_t *t) {
info(_("Target details:\n"));
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Name"), t->name);
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Description"), t->desc);
printf("\n");
}

View File

@ -15,3 +15,4 @@ bool target_is_valid(target_t *);
void target_init(target_t *);
void target_free(target_t *);
bool target_copy(target_t *, bool);
void target_print(target_t *);

View File

@ -111,7 +111,7 @@ bool mksubdirsp(char *path, int perms) {
for (char *c = path; *c != '\0'; c++) {
if (*c == '/' && indx != 0) {
cur[indx] = '\0';
if (!exists(cur) && mkdir(cur, perms) < 0){
if (!exists(cur) && mkdir(cur, perms) < 0) {
error_set(_("Failed to create directory: %s"), cur);
errno = MkdirFail;
return false;
@ -122,7 +122,7 @@ bool mksubdirsp(char *path, int perms) {
indx++;
}
if (!exists(cur) && mkdir(cur, perms) < 0){
if (!exists(cur) && mkdir(cur, perms) < 0) {
error_set(_("Failed to create directory: %s"), cur);
errno = MkdirFail;
return false;
@ -196,12 +196,12 @@ void clist_add(clist_t *l, char *en) {
l->s++;
}
bool copyfile(char *src, char *dst){
bool copyfile(char *src, char *dst) {
FILE *srcf = fopen(src, "r");
FILE *dstf = fopen(dst, "w");
if(NULL == srcf || NULL == dstf){
if(NULL == srcf)
if (NULL == srcf || NULL == dstf) {
if (NULL == srcf)
error_set(_("Failed to open \"%s\" for reading"), srcf);
else
error_set(_("Failed to open \"%s\" for writing"), dstf);
@ -210,11 +210,11 @@ bool copyfile(char *src, char *dst){
}
char buffer[32];
int read = -1;
int read = -1;
bzero(buffer, 32);
while((read = fread(buffer, 1, 32, srcf)) > 0)
while ((read = fread(buffer, 1, 32, srcf)) > 0)
fwrite(buffer, 1, read, dstf);
fclose(srcf);

View File

@ -18,7 +18,7 @@ int randint(int, int);
bool is_dir(char *);
bool mksubdirsp(char *, int);
bool rmrf(char *);
bool copyfile(char *, char *);
bool copyfile(char *, char *);
void clist_init(clist_t *);
void clist_from_str(clist_t *, char *);