shithub: mapfs

Download patch

ref: de249e1277de1639193f4a35da07f50f34b6ff44
parent: 5390510d0ae960fae9a0a9039bb9da3d1f4f969c
author: sirjofri <sirjofri@sirjofri.de>
date: Sun Apr 6 12:14:01 EDT 2025

automatically fetch tiles older than 7 days

--- a/mapfs.c
+++ b/mapfs.c
@@ -10,7 +10,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-s srvname] [-m mtpt] [-c cachedir] [-z maxzoom]\n", argv0);
+	fprint(2, "usage: %s [-s srvname] [-m mtpt] [-c cachedir] [-z maxzoom] [-a maxage]\n", argv0);
 	exits("usage");
 }
 
@@ -25,6 +25,7 @@
 char *cache = "/tmp/mapcache";
 char *uid;
 int maxzoom = 19;
+int maxage = 7;
 
 ulong *numtiles;
 
@@ -293,6 +294,8 @@
 	Bundle b;
 	Qpath path;
 	int fd;
+	Dir *fdir;
+	long age;
 	char buf[128];
 	
 	if (QID(r->fid->qid.path) == Qroot) {
@@ -339,6 +342,15 @@
 	if (access(buf, AEXIST) < 0)
 		requestfile(b, buf);
 	
+	fdir = dirstat(buf);
+	if (fdir) {
+		age = time(nil) - fdir->mtime;
+		if (age > maxage * 60 * 60 * 12)
+			requestfile(b, buf);
+	} else
+		requestfile(b, buf);
+	free(fdir);
+	
 	fd = open(buf, OREAD);
 	if (fd < 0) {
 		responderror(r);
@@ -405,6 +417,9 @@
 		break;
 	case 'z':
 		maxzoom = atoi(EARGF(usage()));
+		break;
+	case 'a':
+		maxage = atoi(EARGF(usage()));
 		break;
 	case 'D':
 		chatty9p++;
--