I am trying to create a directory with public write rights. To simplify things, I want to have permissions 777
. Here is my code:
private static FileAttribute<Set<PosixFilePermission>> DIR_PERMISSIONS;
static {
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
DIR_PERMISSIONS = PosixFilePermissions.asFileAttribute(perms);
}
private Path ensurePath(LocalDate localDate) throws IOException {
String year = String.valueOf(localDate.getYear());
String month = String.format("%02d", localDate.getMonthValue());
Path path = Paths.get(rootDirectory, year, month);
return Files.createDirectories(path, DIR_PERMISSIONS);
}
With rootDirectory=/tmp/data
this should create folders of type /tmp/data/2016/01
, each with permissions 777
. Instead, the folders have permissions 775
(drwxrwxr-x.), So they lack a public record. Why does it work like this? Perhaps the JVM needs a special parameter to be able to set such permissions? My system is Fedora 24, the application is a standard Spring boot application launched by the maven plugin.