Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the OS is POSIX compliant

Tags:

java

posix

nio

nio2

I am writing a cross-platform application that creates temporary files and copies these to another location, where they need to be readable by everyone. (By default, only the owner has read access to temporary files.) I tried using the POSIX file permissions as follows:

FileAttribute<Set<PosixFilePermission>> attrs =   PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-r--r--")); Path temp = Files.createTempFile(null, ".tmp", attrs); 

But this results in an exception on non-POSIX platforms:

java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute 

I want to add a simple check so that I can use the file permissions where necessary, without breaking compatibility with other platforms.

like image 208
Mangara Avatar asked Feb 04 '14 01:02

Mangara


People also ask

Which operating systems are POSIX-compliant?

Examples of some POSIX-compliant systems are AIX, HP-UX, Solaris, and MacOS (since 10.5 Leopard). On the other hand, Android, FreeBSD, Linux Distributions, OpenBSD, VMWare, etc., follow most of the POSIX standard, but they are not certified.

What makes something POSIX-compliant?

Being POSIX-compliant for an OS means that it supports those standards (e.g., APIs), and thus can either natively run UNIX programs, or at least porting an application from UNIX to the target OS is easy/easier than if it did not support POSIX.

Is Linux POSIX-compliant?

For now, Linux is not POSIX-certified due to high costs, except for the two commercial Linux distributions Inspur K-UX [12] and Huawei EulerOS [6]. Instead, Linux is seen as being mostly POSIX-compliant.

Is POSIX an operating system?

POSIX (Portable Operating System Interface) is a set of standard operating system interfaces based on the Unix operating system.


1 Answers

Digging deeper within JDK code, this is the check being used for POSIX

from java.nio.file.TempFileHelper

private static final boolean isPosix =     FileSystems.getDefault().supportedFileAttributeViews().contains("posix"); 

You can use this check.

like image 98
Ajay George Avatar answered Oct 12 '22 04:10

Ajay George