shithub: gefs

Download patch

ref: 41d10374a9636e23ba1fc81fc97a183b9ab565d8
parent: d48bbb88615522a678537ba0eeede9b1f4869388
author: Ori Bernstein <[email protected]>
date: Fri Jan 19 18:19:01 EST 2024

fs: clear out file contents even when the file is QTTMP

there was an incorrect check for QID type when deciding
to clear a file; fix it.

--- a/fs.c
+++ b/fs.c
@@ -1693,16 +1693,15 @@
 	mb[0].nk = f->dent->nk;
 	mb[0].nv = 0;
 
-	packsuper(upbuf, sizeof(upbuf), f->qpath);
-	mb[1].op = Oclobber;
-	mb[1].k = upbuf;
-	mb[1].nk = Upksz;
-	mb[1].nv = 0;
-
-	upsert(f->mnt, mb, 1);
-	if(f->dent->qid.type == QTFILE){
-		if((*ao = malloc(sizeof(Amsg))) == nil)
-			error(Enomem);
+	if(f->dent->qid.type &= QTDIR){
+		packsuper(upbuf, sizeof(upbuf), f->qpath);
+		mb[1].op = Oclobber;
+		mb[1].k = upbuf;
+		mb[1].nk = Upksz;
+		mb[1].nv = 0;
+		upsert(f->mnt, mb, 2);
+	}else{
+		*ao = emalloc(sizeof(Amsg), 1);
 		aincl(&f->mnt->ref, 1);
 		(*ao)->op = AOclear;
 		(*ao)->mnt = f->mnt;
@@ -1710,6 +1709,7 @@
 		(*ao)->off = 0;
 		(*ao)->end = f->dent->length;
 		(*ao)->dent = nil;
+		upsert(f->mnt, mb, 1);
 	}
 	f->dent->gone = 1;
 	r.type = Rremove;