From d7e347175f27aac5badd6d66f210c8ebb179e354 Mon Sep 17 00:00:00 2001 From: ngn Date: Thu, 2 May 2024 23:12:01 +0300 Subject: [PATCH] fix: skip '.' and '..' entries while copying, append home dir to destination paths --- locale/tr/LC_MESSAGES/mc.po | 33 ++++++++++++++------------------- src/config.c | 5 ++++- src/gen.c | 3 +-- src/paths.c | 1 + src/target.c | 7 +++++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/locale/tr/LC_MESSAGES/mc.po b/locale/tr/LC_MESSAGES/mc.po index 3d63f32..36f5e7d 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 22:56+0300\n" +"POT-Creation-Date: 2024-05-02 23:10+0300\n" "PO-Revision-Date: 2024-05-01 13:34+0300\n" "Last-Translator: \n" "Language-Team: Turkish \n" @@ -17,48 +17,48 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: src/config.c:23 +#: src/config.c:24 msgid "Configuration does not have a name field" msgstr "" -#: src/config.c:28 +#: src/config.c:29 msgid "Configuration does not have an author field" msgstr "" -#: src/config.c:33 +#: src/config.c:34 msgid "Configuration does not have any targets" msgstr "" -#: src/config.c:91 +#: src/config.c:92 msgid "Configuration contains multiple targets with the same name" msgstr "" -#: src/config.c:113 +#: src/config.c:116 #, c-format msgid "Key %s is unknown" msgstr "" -#: src/config.c:143 +#: src/config.c:146 msgid "Configuration file not found" msgstr "" -#: src/config.c:158 +#: src/config.c:161 msgid "Failed to parse configuration file" msgstr "" -#: src/config.c:174 +#: src/config.c:177 msgid "Configuration details:\n" msgstr "" -#: src/config.c:175 +#: src/config.c:178 msgid "Name" msgstr "" -#: src/config.c:176 +#: src/config.c:179 msgid "Author" msgstr "" -#: src/config.c:178 +#: src/config.c:181 msgid "Keywords" msgstr "" @@ -86,15 +86,10 @@ msgstr "" msgid "Copying all the targets" msgstr "" -#: src/gen.c:47 +#: src/gen.c:48 msgid "Failed to copy the target:" msgstr "" -#: src/gen.c:53 -#, c-format -msgid "%s: copy success" -msgstr "" - #: src/log.c:145 msgid "y" msgstr "" @@ -221,7 +216,7 @@ msgstr "" msgid "Failed to open the directory: %s" msgstr "" -#: src/target.c:76 +#: src/target.c:79 #, c-format msgid "Source directory \"%s\" does not exist" msgstr "" diff --git a/src/config.c b/src/config.c index 5d4e8c7..7db80eb 100644 --- a/src/config.c +++ b/src/config.c @@ -2,6 +2,7 @@ #include #include +#include "paths.h" #include "config.h" #include "error.h" #include "intl.h" @@ -99,7 +100,9 @@ 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")) { - config->t_last->dst = strdup(value); + int len = strlen(value)+strlen(mc_root)+2; + config->t_last->dst = malloc(len); + join(config->t_last->dst, mc_root, value); return 1; } else if (MATCHKEY("src")) { config->t_last->src = strdup(value); diff --git a/src/gen.c b/src/gen.c index 004de6a..296d726 100644 --- a/src/gen.c +++ b/src/gen.c @@ -44,13 +44,12 @@ bool gen_cmd() { while (cur && ++counter > 0) { if(!target_copy(cur, true)){ + bar_free(); error(_("Failed to copy the target:")); details(errch); - bar_free(); goto END; } - success(_("%s: copy success")); bar(counter, cfg.t_len); cur = cur->next; } diff --git a/src/paths.c b/src/paths.c index 4bd6a3f..85a5feb 100644 --- a/src/paths.c +++ b/src/paths.c @@ -8,6 +8,7 @@ char *mc_lock_path; char *mc_tmp_path; char *mc_root; +char *mc_home; char *mc_dir; char *append_root(char *pth) { diff --git a/src/target.c b/src/target.c index cdeb2bb..02517b3 100644 --- a/src/target.c +++ b/src/target.c @@ -28,7 +28,7 @@ bool target_is_valid(target_t *t) { } bool target_copy_dir(char *src, char *dst) { - if (!mksubdirsp(dst, 755)) + if (!mksubdirsp(dst, 0755)) return false; DIR *dir = opendir(src); @@ -44,6 +44,9 @@ 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; + size_t len = strlen(ent->d_name); char src_fp[src_len + len + 2], dst_fp[dst_len + len + 2]; @@ -72,7 +75,7 @@ bool target_copy(target_t *t, bool fromdst) { dst = t->src; } - if (!exists(t->src)) { + if (!exists(src)) { error_set(_("Source directory \"%s\" does not exist"), src); errno = TargetSrcFail; return ret;