about summary refs log tree commit diff
path: root/concat.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-13 12:00:17 -0400
committerJune McEnroe <june@causal.agency>2020-04-13 12:00:17 -0400
commit2060d70f0574019381cbf6f2c78db941f391224c (patch)
treee4e80d26ee609f4870e6206adcfc2296897a0e6c /concat.c
parentRename atom rendering functions (diff)
downloadbubger-2060d70f0574019381cbf6f2c78db941f391224c.tar.gz
bubger-2060d70f0574019381cbf6f2c78db941f391224c.zip
Rework path functions again
Diffstat (limited to 'concat.c')
-rw-r--r--concat.c52
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);