Skip to content

Commit 5f2e280

Browse files
author
Alan Bateman
committed
8259865: (fs) test/jdk/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java failing on macOS 10.13
Reviewed-by: dcubed
1 parent da4cf05 commit 5f2e280

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/java.base/macosx/classes/sun/nio/fs/BsdFileStore.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.attribute.*;
29-
import java.util.*;
28+
import java.nio.file.attribute.FileAttributeView;
29+
import java.nio.file.attribute.UserDefinedFileAttributeView;
3030
import java.io.IOException;
31+
import java.util.Arrays;
32+
import sun.security.action.GetPropertyAction;
3133

3234
/**
3335
* Bsd implementation of FileStore
@@ -111,9 +113,12 @@ public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type
111113
return false;
112114

113115
// typical macOS file system types that are known to support xattr
114-
if (entry().fstype().equals("apfs")
115-
|| entry().fstype().equals("hfs")) {
116+
String fstype = entry().fstype();
117+
if ("hfs".equals(fstype))
116118
return true;
119+
if ("apfs".equals(fstype)) {
120+
// fgetxattr broken on APFS prior to 10.14
121+
return isOsVersionGte(10, 14);
117122
}
118123

119124
// probe file system capabilities
@@ -129,4 +134,17 @@ public boolean supportsFileAttributeView(String name) {
129134
return supportsFileAttributeView(UserDefinedFileAttributeView.class);
130135
return super.supportsFileAttributeView(name);
131136
}
137+
138+
/**
139+
* Returns true if the OS major/minor version is greater than, or equal, to the
140+
* given major/minor version.
141+
*/
142+
private static boolean isOsVersionGte(int requiredMajor, int requiredMinor) {
143+
String osVersion = GetPropertyAction.privilegedGetProperty("os.version");
144+
String[] vers = Util.split(osVersion, '.');
145+
int majorVersion = Integer.parseInt(vers[0]);
146+
int minorVersion = Integer.parseInt(vers[1]);
147+
return (majorVersion > requiredMajor)
148+
|| (majorVersion == requiredMajor && minorVersion >= requiredMinor);
149+
}
132150
}

0 commit comments

Comments
 (0)