Should Files.createDirectory allow setting of group and other permissions?
Tim Fox
timvolpe at gmail.com
Fri Aug 5 05:50:27 PDT 2011
On 05/08/11 13:40, Alan Bateman wrote:
> Tim Fox wrote:
>> I am calling Files.createDirectory() to create a new directory with a
>> set of Posix file permissions, on Linux. Here is some example code:
>>
>> String perms = "rwxrwxrwx";
>> String dirName = "some-dir";
>> FileAttribute<?> attrs =
>> PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(perms));
>>
>> Files.createDirectory(Paths.get(dirName), attrs);
>> System.out.println(PosixFilePermissions.toString(Files.getPosixFilePermissions(Paths.get(dirName))));
>>
>>
>> Prints out "rwxr-xr-x", not "rwxrwxrwx"
>>
>> If I change perms to "r-xrwxrwx" then it prints out "r-xr-xr-x"
>>
>> I.e. it seems when creating dirs the group and other permissions are
>> ignored, and only the specified user permissions are set.
>>
>> Can anyone clarify whether this is expected behaviour?
>>
>> Thanks
> What is your umask settings?
Yeah, my umask prevents the write bit being set by the process for group
and others, however is it right for Files.createDirectory() to silently
fail to create the directory with the specified permissions, rather than
throw an exception?
If that's expected behaviour, that's fine.
More information about the nio-discuss
mailing list