diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | posts.c | 10 | ||||
-rw-r--r-- | rss.c | 10 | ||||
-rw-r--r-- | skull.c | 2 | ||||
-rw-r--r-- | sm.c | 2 | ||||
-rw-r--r-- | sm.conf | 10 | ||||
-rw-r--r-- | util.c | 24 | ||||
-rw-r--r-- | util.h | 1 |
8 files changed, 52 insertions, 9 deletions
@@ -10,7 +10,7 @@ sm: ${OBJ} ${OBJ}: config.h plugins.h -plugins.h: ${PLUGINS} +plugins.h: config.mk printf '%s\n' ${PLUGINS:.c=} | awk -f genplugin.awk install: @@ -1,4 +1,5 @@ -#include <stdlib.h> +#include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -71,7 +72,12 @@ href=\"mailto:erikk@previousplan.org\">erikk@previousplan.org</a> \ qsort(doc, ndoc, sizeof(*doc), (int (*)(const void *, const void *))creatcompar); - outf = xfopen(kpostsexport, "w"); + if (!mkparentdirs(kpostsexport)) + return; + if ((outf = fopen(kpostsexport, "w")) == NULL) { + fprintf(stderr, "%s: %s\n", kpostsexport, strerror(errno)); + return; + } xfputs(header, outf); for (i = 0; i < ndoc; i++) { my_strlcpy(title, doc[i]->title, sizeof(title)); @@ -1,4 +1,7 @@ +#include <errno.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include "config.h" #include "sm.h" @@ -61,7 +64,12 @@ rssexport(Document **doc, int ndoc) qsort(doc, ndoc, sizeof(*doc), (int (*)(const void *, const void *))creatcompar); - outf = xfopen(krssexport, "w"); + if (!mkparentdirs(krssexport)) + return; + if ((outf = fopen(krssexport, "w")) == NULL) { + fprintf(stderr, "%s: %s\n", krssexport, strerror(errno)); + return; + } for (j = 0; j < LEN(header); j++) xfputs(header[j], outf); for (i = 0; i < ndoc; i++) { @@ -64,6 +64,8 @@ href=\"mailto:erikk@previousplan.org\">erikk@previousplan.org</a> \ snprintf(path, sizeof(path), "%s/%s", kcontentdir, doc[i]->filename); snprintf(outpath, sizeof(outpath), "%s/%s", kskullexport, doc[i]->filename); + if (!mkparentdirs(outpath)) + continue; if ((outf = fopen(outpath, "w")) == NULL) { fprintf(stderr, "%s: %s\n", outpath, strerror(errno)); continue; @@ -339,6 +339,7 @@ edit(const char *filename) return 0; } snprintf(path, sizeof(path), "%s/%s", kcontentdir, filename); + mkparentdirs(path); switch ((pid = fork())) { case -1: fprintf(stderr, "fork: %s\n", strerror(errno)); @@ -362,6 +363,7 @@ list(const char *filename) plugstats[0] = '['; plugstats[NPLUGINS+1] = ']'; + plugstats[NPLUGINS+2] = '\0'; if (filename) { snprintf(path, sizeof(path), "%s/%s", kcontentdir, filename); cat(path, stdout); @@ -1,12 +1,12 @@ -DbLoc ~/sites/sm/previousplan.org.tsv -ContentDir ~/sites/sm/previousplan.org +DbLoc sm.tsv +ContentDir content LinkPreset https://previousplan.org/% Autoedit True Autoexport True -SkullExport ~/sites/previousplan.org +SkullExport export RssTitle Previous Plan! RssDescription Previous Plan! Blog RssLink https://previousplan.org/rss.xml -RssExport ~/sites/previousplan.org/rss.xml -PostsExport ~/sites/previousplan.org/posts.html +RssExport export/rss.xml +PostsExport export/posts.html @@ -1,3 +1,5 @@ +#include <sys/stat.h> + #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -65,6 +67,28 @@ xrealloc(void *ptr, size_t size) return n; } +int +mkparentdirs(const char *path) +{ + char part[512]; + int i; + + if (!path[0]) + return 0; + my_strlcpy(part, path, sizeof(part)); + for (i = 1; part[i]; i++) { + if (part[i] == '/' && part[i + 1] != '/' && part[i + 1]) { + part[i] = '\0'; + if (mkdir(part, 0755) < 0 && errno != EEXIST) { + fprintf(stderr, "mkdir %s: %s\n", part, strerror(errno)); + return 0; + } + part[i] = '/'; + } + } + return 1; +} + /* strlcpy is unportable, and strncpy is a mess. So we define our own strlcpy * instead. */ size_t @@ -6,4 +6,5 @@ FILE *xfopen(const char *, const char *); int xfputs(const char *, FILE *); void *xmalloc(size_t); void *xrealloc(void *, size_t); +int mkparentdirs(const char *); size_t my_strlcpy(char *, const char *, size_t); |