8260966: (fs) Consolidate Linux and macOS implementations of UserDefinedFileAttributeView

8260691: (fs) LinuxNativeDispatcher should link to xattr functions

Reviewed-by: alanb
This commit is contained in:
Sebastian Stenzel 2021-03-02 14:40:45 +00:00 committed by Alan Bateman
parent 5f4bc0aca6
commit 0de6abd4b4
16 changed files with 555 additions and 977 deletions

View file

@ -172,6 +172,31 @@ abstract class UnixFileStore
throw new UnsupportedOperationException("'" + attribute + "' not recognized");
}
/**
* Checks whether extended attributes are enabled on the file system where the given file resides.
*
* @param path A path pointing to an existing node, such as the file system's root
* @return <code>true</code> if enabled, <code>false</code> if disabled or unable to determine
*/
protected boolean isExtendedAttributesEnabled(UnixPath path) {
int fd = -1;
try {
fd = path.openForAttributeAccess(false);
// fgetxattr returns size if called with size==0
byte[] name = Util.toBytes("user.java");
UnixNativeDispatcher.fgetxattr(fd, name, 0L, 0);
return true;
} catch (UnixException e) {
// attribute does not exist
if (e.errno() == UnixConstants.XATTR_NOT_FOUND)
return true;
} finally {
UnixNativeDispatcher.close(fd);
}
return false;
}
@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
if (type == null)