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

View File

@ -2,11 +2,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "paths.h"
#include "config.h" #include "config.h"
#include "error.h" #include "error.h"
#include "intl.h" #include "intl.h"
#include "log.h" #include "log.h"
#include "paths.h"
#include "util.h" #include "util.h"
bool config_contains_target(config_t *config, char *name) { 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_t *new = malloc(sizeof(target_t));
target_init(new); target_init(new);
new->name = name; new->name = name;
config->t_len++; config->t_len++;
if (NULL == config->t_first || NULL == config->t_last) { 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); config->t_last->desc = strdup(value);
return 1; return 1;
} else if (MATCHKEY("dst")) { } 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); config->t_last->dst = malloc(len);
join(config->t_last->dst, mc_root, value); join(config->t_last->dst, mc_root, value);
return 1; return 1;

View File

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

View File

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

View File

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

View File

@ -85,17 +85,48 @@ COPY:
if (!yesno(_("Do you want to continue?"))) if (!yesno(_("Do you want to continue?")))
goto END; goto END;
target_t *cur = repo_cfg.t_first;
int counter = 0;
info(_("Checking all the targets")); info(_("Checking all the targets"));
target_t *cur = repo_cfg.t_first; bar_init();
while (NULL != cur) {
while (NULL != cur && ++counter > 0) {
if (!exists(cur->src)) { if (!exists(cur->src)) {
bar_free();
error(_("Failed to access the source for the target \"%s\""), cur->name); error(_("Failed to access the source for the target \"%s\""), cur->name);
goto END; 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; cur = cur->next;
} }
success(_("All the targets are OK")); ret = true;
END: END:
if (repo_cfg.name != NULL) if (repo_cfg.name != NULL)

View File

@ -1,10 +1,12 @@
#include "target.h" #include "target.h"
#include "error.h" #include "error.h"
#include "intl.h" #include "intl.h"
#include "log.h"
#include "util.h" #include "util.h"
#include <libgen.h>
#include <dirent.h> #include <dirent.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -44,8 +46,8 @@ bool target_copy_dir(char *src, char *dst) {
size_t dst_len = strlen(dst); size_t dst_len = strlen(dst);
while ((ent = readdir(dir)) != NULL) { while ((ent = readdir(dir)) != NULL) {
if(eq(ent->d_name, ".") || eq(ent->d_name, "..")) if (eq(ent->d_name, ".") || eq(ent->d_name, ".."))
continue; continue;
size_t len = strlen(ent->d_name); size_t len = strlen(ent->d_name);
char src_fp[src_len + len + 2], dst_fp[dst_len + len + 2]; 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) { bool target_copy(target_t *t, bool fromdst) {
char *src = t->src, *dst = t->dst; char *src = t->src, *dst = t->dst;
bool ret = false; bool ret = false;
if (fromdst) { if (fromdst) {
src = t->dst; src = t->dst;
@ -84,10 +86,10 @@ bool target_copy(target_t *t, bool fromdst) {
if (is_dir(src)) if (is_dir(src))
return target_copy_dir(src, dst); return target_copy_dir(src, dst);
char *dstcp = strdup(dst); char *dstcp = strdup(dst);
char *dstdir = dirname(dst); char *dstdir = dirname(dst);
if(!mksubdirsp(dstdir, 0755)) if (!mksubdirsp(dstdir, 0755))
return ret; return ret;
ret = copyfile(src, dstcp); ret = copyfile(src, dstcp);
@ -111,3 +113,10 @@ void target_free(target_t *t) {
free(t->src); free(t->src);
clist_free(&t->requires); 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_init(target_t *);
void target_free(target_t *); void target_free(target_t *);
bool target_copy(target_t *, bool); 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++) { for (char *c = path; *c != '\0'; c++) {
if (*c == '/' && indx != 0) { if (*c == '/' && indx != 0) {
cur[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); error_set(_("Failed to create directory: %s"), cur);
errno = MkdirFail; errno = MkdirFail;
return false; return false;
@ -122,7 +122,7 @@ bool mksubdirsp(char *path, int perms) {
indx++; indx++;
} }
if (!exists(cur) && mkdir(cur, perms) < 0){ if (!exists(cur) && mkdir(cur, perms) < 0) {
error_set(_("Failed to create directory: %s"), cur); error_set(_("Failed to create directory: %s"), cur);
errno = MkdirFail; errno = MkdirFail;
return false; return false;
@ -196,12 +196,12 @@ void clist_add(clist_t *l, char *en) {
l->s++; l->s++;
} }
bool copyfile(char *src, char *dst){ bool copyfile(char *src, char *dst) {
FILE *srcf = fopen(src, "r"); FILE *srcf = fopen(src, "r");
FILE *dstf = fopen(dst, "w"); FILE *dstf = fopen(dst, "w");
if(NULL == srcf || NULL == dstf){ if (NULL == srcf || NULL == dstf) {
if(NULL == srcf) if (NULL == srcf)
error_set(_("Failed to open \"%s\" for reading"), srcf); error_set(_("Failed to open \"%s\" for reading"), srcf);
else else
error_set(_("Failed to open \"%s\" for writing"), dstf); error_set(_("Failed to open \"%s\" for writing"), dstf);
@ -210,11 +210,11 @@ bool copyfile(char *src, char *dst){
} }
char buffer[32]; char buffer[32];
int read = -1; int read = -1;
bzero(buffer, 32); bzero(buffer, 32);
while((read = fread(buffer, 1, 32, srcf)) > 0) while ((read = fread(buffer, 1, 32, srcf)) > 0)
fwrite(buffer, 1, read, dstf); fwrite(buffer, 1, read, dstf);
fclose(srcf); fclose(srcf);

View File

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