Ich habe mir mal eine Funktion zum erstellen eines Verzeichnisses, unabhängig von ACL und Posix erstellt. Bis jetzt sieht meine Funktion wie folgt aus:
Ich kenne zwar die Funktionen isWritable() und Co, allerdings weis ich nicht ob z.B. isWritable() bei ACL und Posix - Systemen funktioniert. Vielleicht denke ich auch zu kompliziert und es gibt einen einfacheren Weg garantiert beschreibbare Verzeichnisse zu erstellen und sie beschreibbar zu machen.
Weil ich mir beim besten Willen nicht vorstellen kann, dass ich der erste bin der auf dieses Problem stößt und somit nicht bereits eine Funktion existiert.
Java:
public boolean createXMLUploadDirectory() throws IOException {
boolean ret = false;
Path xmlDirectoryPath = this.getXMLUploadDirectory();
if (!Files.exists(xmlDirectoryPath)) {
LOGGER.info("create directory: " + xmlDirectoryPath);
FileAttribute<?> fileAttributes;
FileStore fileStore = Files.getFileStore(xmlDirectoryPath);
if(fileStore.supportsFileAttributeView("posix")) {
LOGGER.info("Posix File System");
// Linux(POSIX) - System
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
fileAttributes = PosixFilePermissions.asFileAttribute(perms);
} else if(fileStore.supportsFileAttributeView("acl")) {
LOGGER.info("ACL File System");
// Windows(ACL) - System
fileAttributes = new FileAttribute<List<AclEntry>>() {
@Override
public List<AclEntry> value() {
// lookup user principal
FileSystem fileSystem = FileSystems.getDefault();
UserPrincipalLookupService userPrincipalLookupService = fileSystem.getUserPrincipalLookupService();
UserPrincipal userPrincipal = null;
try {
userPrincipal = userPrincipalLookupService.lookupPrincipalByName("JStas");
} catch (IOException e) {
throw new RuntimeException(e);
}
// select ACL flags
Set<AclEntryFlag> flags = EnumSet.of(AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT);
// select ACL permission
Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA, AclEntryPermission.WRITE_DATA, AclEntryPermission.EXECUTE);
// build ACL entry
Builder builder = AclEntry.newBuilder();
builder.setFlags(flags);
builder.setPermissions(permissions);
builder.setPrincipal(userPrincipal);
builder.setType(AclEntryType.DENY);
AclEntry entry = builder.build();
List<AclEntry> aclEntryList = new ArrayList<>();
aclEntryList.add(entry);
return aclEntryList;
}
@Override
public String name() {
return "acl:acl";
}
};
} else {
String msg = "no recognized attribute view";
LOGGER.error(msg);
throw new UnsupportedOperationException(msg);
}
Files.createDirectory(xmlDirectoryPath, fileAttributes);
ret = true;
} else {
// sicherstellen dass Verzeichnis existiert und schreibzugriffe erlaubt.
}
Ich kenne zwar die Funktionen isWritable() und Co, allerdings weis ich nicht ob z.B. isWritable() bei ACL und Posix - Systemen funktioniert. Vielleicht denke ich auch zu kompliziert und es gibt einen einfacheren Weg garantiert beschreibbare Verzeichnisse zu erstellen und sie beschreibbar zu machen.
Weil ich mir beim besten Willen nicht vorstellen kann, dass ich der erste bin der auf dieses Problem stößt und somit nicht bereits eine Funktion existiert.