fix: skip '.' and '..' entries while copying, append home dir to destination paths
This commit is contained in:
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user