shithub: mc

Download patch

ref: e9e1587410a24b8ae4de292296ed441bddb98f4b
parent: 983a758d3127bf5d861227e6a9c56900bf6e2da8
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Oct 6 19:40:07 EDT 2015

Change mkpath API a bit.

    We want to pass through modes and handle errors properly.

--- a/lib/std/mkpath.myr
+++ b/lib/std/mkpath.myr
@@ -2,20 +2,20 @@
 use "errno.use"
 
 pkg std =
-	const mkpath	: (p : byte[:] -> bool)
+	const mkpath	: (p : byte[:], mode : int64 -> errno)
 ;;
 
-const mkpath = {p
+const mkpath = {p, mode
 	var st
 
 	for var i = 0; i < p.len; i++
 		if p[i] == '/' castto(byte) && i != 0
-			st = mkdir(p[:i], 0o777)
-			if st != 0 && (st castto(errno)) != Eexist
-				-> false
+			st = mkdir(p[:i], mode)
+			if st != 0 && st != Eexist
+				-> st
 			;;
 		;;
 	;;
 
-	-> true
+	-> Enone
 }
--- a/lib/std/syswrap+plan9.myr
+++ b/lib/std/syswrap+plan9.myr
@@ -54,7 +54,7 @@
 	const getsysinfo	: (si : sysinfo# -> void)
 
 	/* path manipulation */
-	const mkdir	: (path : byte[:], mode : int64 -> int64)
+	const mkdir	: (path : byte[:], mode : int64 -> errno)
 	const chdir	: (path : byte[:] -> bool)
 	const remove	: (path : byte[:] -> bool)
 
@@ -153,7 +153,7 @@
 
 	fd = sys.create(path, sys.Ordonly, sys.Dmdir | (mode castto(int)))
 	if fd < 0
-		-> -1
+		-> lasterr()
 	;;
 	sys.close(fd)
 	-> 0
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -52,7 +52,7 @@
 	const getsysinfo	: (si : sysinfo# -> void)
 
 	/* path manipulation */
-	const mkdir	: (path : byte[:], mode : int64 -> int64)
+	const mkdir	: (path : byte[:], mode : int64 -> errno)
 	const remove	: (path : byte[:] -> bool)
 	const chdir	: (path : byte[:] -> bool)
 
@@ -83,7 +83,7 @@
 const dup2	= {ofd, nfd;	-> check(sys.dup2(ofd castto(sys.fd), nfd castto(sys.fd)) castto(fd))}
 
 /* path manipulation */
-const mkdir	= {path, mode;	-> sys.mkdir(path, mode)}
+const mkdir	= {path, mode;	-> sys.mkdir(path, mode) castto(errno)}
 const chdir	= {path;	-> sys.chdir(path) == 0}
 const remove	= {path;	-> sys.unlink(path) == 0}