diff options
Diffstat (limited to '')
-rw-r--r-- | concat.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/concat.c b/concat.c index 5e8be3d..abf648c 100644 --- a/concat.c +++ b/concat.c @@ -53,14 +53,13 @@ void concatFetch(FILE *imap, enum Atom tag, struct List threads) { } static time_t uidNewest(struct List uids, const char *type) { - char path[PATH_MAX]; time_t newest = 0; for (size_t i = 0; i < uids.len; ++i) { - pathUID(path, dataCheck(uids.ptr[i], Number).number, type); - struct stat file; - int error = stat(path, &file); + const char *path = pathUID(dataCheck(uids.ptr[i], Number).number, type); + struct stat status; + int error = stat(path, &status); if (error) err(EX_DATAERR, "%s", path); - if (file.st_mtime > newest) newest = file.st_mtime; + if (status.st_mtime > newest) newest = status.st_mtime; } return newest; } @@ -78,7 +77,6 @@ static int concatFile(FILE *dst, const char *path) { } static int concatHTML(FILE *file, struct List thread) { - static char path[PATH_MAX]; int error; for (size_t i = 0; i < thread.len; ++i) { if (thread.ptr[i].type == List) { @@ -86,7 +84,7 @@ static int concatHTML(FILE *file, struct List thread) { } else { uint32_t uid = dataCheck(thread.ptr[i], Number).number; error = htmlThreadOpen(file) - || concatFile(file, pathUID(path, uid, "html")); + || concatFile(file, pathUID(uid, "html")); } if (error) return error; } @@ -121,47 +119,49 @@ void concatData(struct List threads, struct List items) { int error; FILE *file; + const char *path; struct stat status; - char dst[PATH_MAX]; - char src[PATH_MAX]; - error = stat(pathThread(dst, envelope.messageID, "mbox"), &status); + path = pathThread(envelope.messageID, "mbox"); + error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "mbox")) { - file = fopen(dst, "w"); - if (!file) err(EX_CANTCREAT, "%s", dst); + file = fopen(path, "w"); + if (!file) err(EX_CANTCREAT, "%s", path); for (size_t i = 0; i < flat.len; ++i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; - error = concatFile(file, pathUID(src, uid, "mbox")); - if (error) err(EX_IOERR, "%s", dst); + error = concatFile(file, pathUID(uid, "mbox")); + if (error) err(EX_IOERR, "%s", path); } error = fclose(file); - if (error) err(EX_IOERR, "%s", dst); + if (error) err(EX_IOERR, "%s", path); } - error = stat(pathThread(dst, envelope.messageID, "atom"), &status); + path = pathThread(envelope.messageID, "atom"); + error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "atom")) { - FILE *file = fopen(dst, "w"); - if (!file) err(EX_CANTCREAT, "%s", dst); + FILE *file = fopen(path, "w"); + if (!file) err(EX_CANTCREAT, "%s", path); error = atomFeedOpen(file, &envelope); - if (error) err(EX_IOERR, "%s", dst); + if (error) err(EX_IOERR, "%s", path); for (size_t i = 0; i < flat.len; ++i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; - error = concatFile(file, pathUID(src, uid, "atom")); - if (error) err(EX_IOERR, "%s", dst); + error = concatFile(file, pathUID(uid, "atom")); + if (error) err(EX_IOERR, "%s", path); } error = atomFeedClose(file) || fclose(file); - if (error) err(EX_IOERR, "%s", dst); + if (error) err(EX_IOERR, "%s", path); } - error = stat(pathThread(dst, envelope.messageID, "html"), &status); + path = pathThread(envelope.messageID, "html"); + error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "html")) { - FILE *file = fopen(dst, "w"); - if (!file) err(EX_CANTCREAT, "%s", dst); + FILE *file = fopen(path, "w"); + if (!file) err(EX_CANTCREAT, "%s", path); error = 0 || htmlThreadHead(file, &envelope) // TODO: Include -h file. @@ -169,7 +169,7 @@ void concatData(struct List threads, struct List items) { || concatHTML(file, thread) || htmlThreadTail(file) || fclose(file); - if (error) err(EX_IOERR, "%s", dst); + if (error) err(EX_IOERR, "%s", path); } listFree(flat); |