Tôi đang cố gắng tạo thư mục có quyền ghi công khai. Để đơn giản hóa mọi thứ tôi muốn nó có các quyền hạn 777
. Dưới đây là mã của tôi:Java - không thể tạo thư mục có quyền 777 (thay vì 775)
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);
}
Với rootDirectory=/tmp/data
này nên tạo các thư mục như /tmp/data/2016/01
, mỗi 777
quyền. Thay vào đó các thư mục có quyền truy cập 775
(drwxrwxr-x.) Để chúng thiếu viết công khai. Tại sao nó hoạt động theo cách này? Có lẽ JVM cần param đặc biệt để có thể thiết lập các điều khoản như vậy? Hệ thống của tôi là Fedora 24, ứng dụng là ứng dụng Khởi động Spring chuẩn, bắt đầu bằng plugin maven.
@ OlivierGrégoire Nó không phải là một bản sao bởi vì điều đó không giải thích * tại sao * nó sắp ra là 775. – Michael
@Michael Phần chính của câu hỏi ở đây là "Tôi không thể", không phải "tại sao". Câu trả lời được chấp nhận trong chủ đề khác hoàn tất như cách khắc phục điều đó. –
@ OlivierGrégoire "** Tại sao ** nó hoạt động theo cách này?" – Michael