shithub: unionfs

Download patch

ref: d2010111e3dd109a44dc91de16eadb82ddd1dd5e
parent: c3bf2ea3ec3ef2cf5e37d26015f2c32dda4f5732
author: kvik <kvik@a-b.xyz>
date: Wed May 15 17:02:14 EDT 2019

use cleanname(2) (through mkpath) to implement walking backwards

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