Skip to content
Snippets Groups Projects
Commit dd07ad17 authored by Brian Burkhalter's avatar Brian Burkhalter
Browse files

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
parent 800f9ab5
No related branches found
No related tags found
No related merge requests found
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { ...@@ -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); (*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->st_birthtime);
#endif #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_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_mtime_nsec, (jlong)buf->st_mtim.tv_nsec);
(*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctim.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 #endif
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* questions. * questions.
*/ */
import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -36,7 +37,7 @@ import static org.testng.Assert.assertFalse; ...@@ -36,7 +37,7 @@ import static org.testng.Assert.assertFalse;
/** /**
* @test * @test
* @bug 4313887 8062949 * @bug 4313887 8062949 8191872
* @library .. * @library ..
* @run testng SetLastModifiedTime * @run testng SetLastModifiedTime
* @summary Unit test for Files.setLastModifiedTime * @summary Unit test for Files.setLastModifiedTime
...@@ -114,5 +115,20 @@ public class SetLastModifiedTime { ...@@ -114,5 +115,20 @@ public class SetLastModifiedTime {
assertTrue(false); assertTrue(false);
} catch (NullPointerException expected) { } } 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()");
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment