diff --git a/locale/tr/LC_MESSAGES/mc.po b/locale/tr/LC_MESSAGES/mc.po index 36f5e7d..f19b3da 100644 --- a/locale/tr/LC_MESSAGES/mc.po +++ b/locale/tr/LC_MESSAGES/mc.po @@ -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: \n" "Language-Team: Turkish \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" diff --git a/src/config.c b/src/config.c index 7db80eb..1b4a23f 100644 --- a/src/config.c +++ b/src/config.c @@ -2,11 +2,11 @@ #include #include -#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; diff --git a/src/config.h b/src/config.h index cf066b8..2b8eaeb 100644 --- a/src/config.h +++ b/src/config.h @@ -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; diff --git a/src/error.h b/src/error.h index 02f681c..f6431e5 100644 --- a/src/error.h +++ b/src/error.h @@ -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; diff --git a/src/gen.c b/src/gen.c index 296d726..925a2dd 100644 --- a/src/gen.c +++ b/src/gen.c @@ -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; } diff --git a/src/pull.c b/src/pull.c index d7a62bc..ba0c7f5 100644 --- a/src/pull.c +++ b/src/pull.c @@ -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) diff --git a/src/target.c b/src/target.c index 02517b3..c159bf5 100644 --- a/src/target.c +++ b/src/target.c @@ -1,10 +1,12 @@ #include "target.h" #include "error.h" #include "intl.h" +#include "log.h" #include "util.h" -#include #include +#include +#include #include #include @@ -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"); +} diff --git a/src/target.h b/src/target.h index 228f585..4f89449 100644 --- a/src/target.h +++ b/src/target.h @@ -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 *); diff --git a/src/util.c b/src/util.c index 4acee32..ed57ed1 100644 --- a/src/util.c +++ b/src/util.c @@ -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); diff --git a/src/util.h b/src/util.h index 6347ea4..66d9963 100644 --- a/src/util.h +++ b/src/util.h @@ -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 *);