8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
Remove POSIX conditional compilation and correct stat64 times for macOS Reviewed-by: alanb, simonis
This commit is contained in:
parent
800f9ab58a
commit
dd07ad1703
src/java.base/unix/native/libnio/fs
test/jdk/java/nio/file/Files
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -476,10 +476,14 @@ static void prepAttributes(JNIEnv* env, struct stat64* buf, jobject attrs) {
|
||||
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->st_birthtime);
|
||||
#endif
|
||||
|
||||
#if (_POSIX_C_SOURCE >= 200809L) || defined(__solaris__)
|
||||
#ifndef MACOSX
|
||||
(*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atim.tv_nsec);
|
||||
(*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtim.tv_nsec);
|
||||
(*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctim.tv_nsec);
|
||||
#else
|
||||
(*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atimespec.tv_nsec);
|
||||
(*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtimespec.tv_nsec);
|
||||
(*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctimespec.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,6 +21,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -36,7 +37,7 @@ import static org.testng.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 4313887 8062949
|
||||
* @bug 4313887 8062949 8191872
|
||||
* @library ..
|
||||
* @run testng SetLastModifiedTime
|
||||
* @summary Unit test for Files.setLastModifiedTime
|
||||
@ -114,5 +115,20 @@ public class SetLastModifiedTime {
|
||||
assertTrue(false);
|
||||
} catch (NullPointerException expected) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompare() throws Exception {
|
||||
Path path = Files.createFile(testDir.resolve("path"));
|
||||
long timeMillis = 1512520600195L;
|
||||
FileTime fileTime = FileTime.fromMillis(timeMillis);
|
||||
Files.setLastModifiedTime(path, fileTime);
|
||||
File file = path.toFile();
|
||||
long ioTime = file.lastModified();
|
||||
long nioTime = Files.getLastModifiedTime(path).toMillis();
|
||||
assertTrue(ioTime == timeMillis || ioTime == 1000*(timeMillis/1000),
|
||||
"File.lastModified() not in {time, 1000*(time/1000)}");
|
||||
assertEquals(nioTime, ioTime,
|
||||
"File.lastModified() != Files.getLastModifiedTime().toMillis()");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user