commit ca5ed11b330ed22036c39a4ca2abd4f86438e4d0
parent 4bce9fcdcf6f159e363dcf569e0f346fc3fb90c7
Author: Paco Esteban <paco@e1e0.net>
Date: Thu, 18 Jun 2020 18:57:32 +0200
clean up a bit process_dir
Diffstat:
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/ssnail.c b/ssnail.c
@@ -368,6 +368,7 @@ process_dir(char *src, char *dst, int force)
char *src_path = NULL, *dst_path = NULL;
+ /* if dst folder does not exist, create it */
if (stat(dst, &st) == -1 && errno == ENOENT) {
if (mkdir(dst, 0755) == -1)
return -1;
@@ -389,7 +390,6 @@ process_dir(char *src, char *dst, int force)
if (dp->d_type == DT_REG) {
if (strcmp(get_filename_ext(src_path), "md") == 0) {
char *fbuf = NULL;
- int n = 0;
a = malloc(sizeof(struct article));
@@ -399,7 +399,7 @@ process_dir(char *src, char *dst, int force)
free(fbuf);
if((populate_article_entry(a) == -1))
- err(2, "cannot populate article");
+ goto out;
SLIST_INSERT_HEAD(&head, a, entries);
} else {
if (copy_file(src_path, dst_path, force) == -1)
@@ -410,10 +410,6 @@ process_dir(char *src, char *dst, int force)
if (process_dir(src_path, dst_path, force) == -1)
goto out;
}
- free(src_path);
- free(dst_path);
- src_path = NULL;
- dst_path = NULL;
}
retval = 0;
@@ -421,6 +417,8 @@ process_dir(char *src, char *dst, int force)
out:
free(src_path);
free(dst_path);
+ src_path = NULL;
+ dst_path = NULL;
closedir(dirp);
return retval;
}