git: 9front

Download patch

ref: 2dd476e3176b0f9da75c1be5824bfb25e0965ab8
parent: eefa37153ed374f925ad701a40eb8f8629252496
author: David Arroyo <david@arroyo.cc>
date: Sat Nov 8 18:07:29 EST 2025

upas: make parent directories for index

(apologies if this is a duplicate, I sent it earlier today but my
mail gateway wasn't playing ball)

Commit 200434baba1610a070122d3c59f95f3667654b43 (upas/fs: give imap
indexes a stable name) changed index file locations to mirror imap
folder locations, instead of the user-provided label.  Which is good,
but I have nested imap folders on my mail server, and would get errors
such as:

wridxfile: file does not exist: '.../glenda/imap.imap.fastmail.com.droyo@fastmail.com.ml/googlegroups'

This patch creates any intermediate directories if the index doesn't
exist yet.

--- a/sys/src/cmd/upas/fs/idx.c
+++ b/sys/src/cmd/upas/fs/idx.c
@@ -229,6 +229,23 @@
 	return 0;
 }
 
+static int
+mkparentdir(char *path)
+{
+	int fd;
+	char *p;
+	for(p = strchr(path+1, '/'); p; p = strchr(p+1, '/')){
+		*p = 0;
+		fd = create(path, OEXCL, DMDIR|0777);
+		*p = '/';
+
+		if(fd < 0 && bad(ecreate))
+			return fd;
+		close(fd);
+	}
+	return 0;
+}
+
 /*
  * n.b.: we don't ensure this is the index version we last read.
  *
@@ -245,6 +262,10 @@
 	Biobuf b;
 	Dir *d, n;
 
+	if(access(mb->path, AEXIST) != 0 && mkparentdir(mb->path) < 0){
+		eprint("wridxfile: mkdir %s/..: %r\n", mb->path);
+		return -1;
+	}
 	snprint(buf, sizeof buf, "%s.idx.tmp", mb->path);
 	iprint("wridxfile %s\n", buf);
 	if((fd = exopen(buf)) == -1){
--