Reputation: 738
Could somebody explain me, why writing permission isn't set for others by the following code snippet on Ubuntu 13.04 and java 1.7 (OpenJDK 64bit). All other permissions are set correctly, except the writing for others, which I think is suspicious.
public void testCreateFileWithPermissions() throws IOException {
Path target = Paths.get(TEST_FILE);
cadf.createFileWithPermissions(target, "rwxrwxrwx");
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(target);
for (PosixFilePermission perm : perms) {
System.out.println(perm.toString());
}
}
public void createFileWithPermissions(Path target, String permissions)
throws IOException {
Set<PosixFilePermission> perms = PosixFilePermissions
.fromString(permissions);
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions
.asFileAttribute(perms);
Files.createFile(target, attr);
}
I got the following output:
OWNER_WRITE
OTHERS_EXECUTE
GROUP_READ
OWNER_READ
GROUP_EXECUTE
GROUP_WRITE
OWNER_EXECUTE
OTHERS_READ
Upvotes: 4
Views: 1098
Reputation: 969
Since changing the umask was no option for me I use Files.setPosixFilePermissions(Path, Set<PosixFilePermission>)
after creating the file.
Upvotes: 2