Files.createFile() does not ignore umask on Unix systems, is this expected?
Francis Galiegue
fgaliegue at gmail.com
Sat Dec 20 09:55:50 UTC 2014
Consider the following test program (imports omitted for brevity):
----
public class Test
{
public static void main(final String... args)
throws IOException
{
final Path toCreate = Paths.get("testdir");
Files.deleteIfExists(toCreate);
final Set<PosixFilePermission> perms
= PosixFilePermissions.fromString("rw-rw-rw-");
final FileAttribute<?> attr
= PosixFilePermissions.asFileAttribute(perms);
final Path created = Files.createFile(toCreate, attr);
final Set<PosixFilePermission> actualPerms
= Files.getPosixFilePermissions(created);
System.out.println(PosixFilePermissions.toString(actualPerms));
System.exit(0);
}
}
----
Now, when running this, I get the following results:
----
fge at alustriel:/tmp$ umask
0027
fge at alustriel:/tmp$ javac -version; java -version
javac 1.8.0_25
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
fge at alustriel:/tmp$ javac Test.java
fge at alustriel:/tmp$ java Test
rw-r-----
fge at alustriel:/tmp$ source ~/.jdk/7;javac -version; java -version
javac 1.7.0_72
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
fge at alustriel:/tmp$ javac Test.java
fge at alustriel:/tmp$ java Test
rw-r-----
----
Which means that despite my specifying a 666 mode for creation, the
umask did apply. I'd have expected it not to...
The documentation does not say anything about this particular
scenario, but it this the intended behaviour?
--
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)
More information about the nio-dev
mailing list