22
22
*/
23
23
24
24
/* @test
25
- * @bug 8181493
25
+ * @bug 8181493 8231174
26
26
* @summary Verify that nanosecond precision is maintained for file timestamps
27
- * @requires (os.family == "linux") | (os.family == "mac") | (os.family == "solaris")
27
+ * @requires (os.family == "linux") | (os.family == "mac") | (os.family == "solaris") | (os.family == "windows")
28
28
* @modules java.base/sun.nio.fs:+open
29
29
*/
30
30
40
40
import java .util .concurrent .TimeUnit ;
41
41
42
42
public class SetTimesNanos {
43
+ private static final boolean IS_WINDOWS =
44
+ System .getProperty ("os.name" ).startsWith ("Windows" );
45
+
43
46
public static void main (String [] args ) throws Exception {
44
- // Check whether futimens() system call is supported
45
- Class unixNativeDispatcherClass = Class .forName ("sun.nio.fs.UnixNativeDispatcher" );
46
- Method futimensSupported = unixNativeDispatcherClass .getDeclaredMethod ("futimensSupported" );
47
- futimensSupported .setAccessible (true );
48
- if (!(boolean )futimensSupported .invoke (null )) {
49
- System .err .println ("futimens() system call not supported; skipping test" );
50
- return ;
47
+ if (!IS_WINDOWS ) {
48
+ // Check whether futimens() system call is supported
49
+ Class unixNativeDispatcherClass =
50
+ Class .forName ("sun.nio.fs.UnixNativeDispatcher" );
51
+ Method futimensSupported =
52
+ unixNativeDispatcherClass .getDeclaredMethod ("futimensSupported" );
53
+ futimensSupported .setAccessible (true );
54
+ if (!(boolean )futimensSupported .invoke (null )) {
55
+ System .err .println ("futimens() not supported; skipping test" );
56
+ return ;
57
+ }
51
58
}
52
59
53
60
Path dirPath = Path .of ("test" );
@@ -56,7 +63,8 @@ public static void main(String[] args) throws Exception {
56
63
System .out .format ("FileStore: \" %s\" on %s (%s)%n" ,
57
64
dir , store .name (), store .type ());
58
65
59
- Set <String > testedTypes = Set .of ("apfs" , "ext4" , "xfs" , "zfs" );
66
+ Set <String > testedTypes = IS_WINDOWS ?
67
+ Set .of ("NTFS" ) : Set .of ("apfs" , "ext4" , "xfs" , "zfs" );
60
68
if (!testedTypes .contains (store .type ())) {
61
69
System .err .format ("%s not in %s; skipping test" , store .type (), testedTypes );
62
70
return ;
@@ -77,6 +85,11 @@ private static void testNanos(Path path) throws IOException {
77
85
Files .getFileAttributeView (path , BasicFileAttributeView .class );
78
86
view .setTimes (pathTime , pathTime , null );
79
87
88
+ // Windows file time resolution is 100ns so truncate
89
+ if (IS_WINDOWS ) {
90
+ timeNanos = 100L *(timeNanos /100L );
91
+ }
92
+
80
93
// Read attributes
81
94
BasicFileAttributes attrs =
82
95
Files .readAttributes (path , BasicFileAttributes .class );
0 commit comments