shithub: unionfs

Download patch

ref: c3bf2ea3ec3ef2cf5e37d26015f2c32dda4f5732
parent: 7479818ad25599c69b879cc8825aeb0e90f124b3
author: kvik <kvik@a-b.xyz>
date: Wed May 15 16:45:03 EDT 2019

fix walking backwards

changing the fspath of the parent Fil structure
caused the subsequent operations on the parent
very confused. instead we copy the path and
change it freely.

--- a/unionfs.c
+++ b/unionfs.c
@@ -326,29 +326,35 @@
 filewalk(Fil *p, char *name)
 {
 	char *path;
-	char *s;
+	char *s, *q;
 	Dir *d;
 	Fil *f;
 	Union *u;
 	
+	q = estrdup(p->fspath);
 	if(strcmp(name, "..") == 0){
-		if((s = strrchr(p->fspath, '/')) == nil)
+		if((s = strrchr(q, '/')) == nil){
+			free(q);
+			filefree(p);
 			return root;
+		}
 		*s = 0;
 		name = "";
 	}
 	for(u = unionlist->next; u != unionlist; u = u->next){
-		path = mkpath(u->root, p->fspath, name, nil);
+		path = mkpath(u->root, q, name, nil);
 		if(d = dirstat(path)){
 			f = filenew(d);
 			free(d);
-			f->fspath = mkpath(p->fspath, name, nil);
+			f->fspath = mkpath(q, name, nil);
 			f->path = path;
 			filefree(p);
+			free(q);
 			return f;
 		}
 		free(path);
 	}
+	free(q);
 	return nil;
 }