From b43941fed25f8411b70d27fc9d7c9c54f83516d8 Mon Sep 17 00:00:00 2001
From: Philipp Gesang <phg@phi-gamma.net>
Date: Fri, 20 Nov 2015 23:23:13 +0100
Subject: [PATCH] lfs: restore umask in mkdir()

Address issue #956

The ``mkdir`` function of the luafilesystem library sets a different
umask when creating directories. However, when the operation fails, the
original mask is never restored. As a consequence, Luatex will create
files with a 0666 mask afterwards (e. g. the PDF or a Latex ``.aux``
file)

The fix is to restore the umask earlier, before checking whether the
operation succeded.
---
 source/texk/web2c/luatexdir/luafilesystem/src/lfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c b/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c
index a0b967d..89015d2 100644
--- a/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c
+++ b/source/texk/web2c/luatexdir/luafilesystem/src/lfs.c
@@ -381,12 +381,12 @@ static int make_dir (lua_State *L) {
 	fail =  mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
 	                     S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
 #endif
+	umask (oldmask);
 	if (fail) {
 		lua_pushnil (L);
         lua_pushfstring (L, "%s", strerror(errno));
 		return 2;
 	}
-	umask (oldmask);
 	lua_pushboolean (L, 1);
 	return 1;
 }
-- 
2.6.2

