fix: skip '.' and '..' entries while copying, append home dir to destination paths

This commit is contained in:
ngn
2024-05-02 23:12:01 +03:00
parent 3bc3c7b8db
commit d7e347175f
5 changed files with 25 additions and 24 deletions

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;