-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1610: add nanosecond resolution in javalib FileTime & posixlib sys/stat; requires previous PRs #1635
Fix #1610: add nanosecond resolution in javalib FileTime & posixlib sys/stat; requires previous PRs #1635
Conversation
…& posixlib sys/stat * This PR fixes Issue scala-native#1610 "SN only supports seconds resolution for FileTime". My thanks to @avdv for detecting & reporting this issue. Nanosecond resolutions are now supported in both javalib FileTime and posixlib sys/stat where the underlying operating and file systems support nanoseconds. * **THIS CHANGE REQUIRES CHANGES TO EXISTING APPLICATIONS WHICH USE TIME FIELDS IN `struct stat`.** The required changes are described in new edits to `docs/lib/posixlib` and `docs/lib/javalib`. * Instant.scala was upgraded only to the point of allowing this PR. Extensive work, beyond the scope of this PR, is needed in `java.date.time`. * A unit test was added to `java/nio/file/FilesSuite.scala` to set and read a nanosecond file time. This test was designed to work where nanosecond file times are supported and not fail where they are not. * The test suite `java/time/InstantSuite.scala` was added to validate Instant.scala. Documentation: * The standard changelog entry is requested. * `docs/lib/javalib.rst` and `docs/lib/posixlib.rst` have each been edited to describe the changes of this PR and how to adapt existing code. Testing: * Built and tested ("test-all") in debug mode using sbt 1.2.8 on X86_64 only . All tests pass.
Hi. Just to note, this does not work on macOS:
|
@avdv Thank you for reporting this. Sorry that it failed and took your time. There is almost certainly a case of a #define (my guess: __USE_XOPEN2K8) being setup Unfortunately, I do not have ready access to an Apple system. Which Apple system are (Sorry if I am too concrete below. I am trying to save you probably quite limited time.) If you have time to aid with debugging, could you kindly execute and post (or create git, or
I am looking to see if APPLE or such is defined (along with various 64 bit defines). Then, if the Apple license allows could you post the contents of the file which defines I an looking to see why the 64 bit definitions are not picked up. Thank you for your help. Lee |
@LeeTibbert This may not be the exact one used but looks very close to the one on my system. |
I found another resource: https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/stat.h.auto.html Also, according to https://sourceforge.net/p/predef/wiki/OperatingSystems/ there should be a preprocessor variable called
|
Oh BTW, I do not use a Mac, this was on Travis: https://travis-ci.com/avdv/scalals/jobs/258405832#L1684 |
I ran some tests. Found that on OSX there is a
And the time members of the
The following code compiles for Linux and OSX:
See https://travis-ci.com/avdv/scalals/jobs/260362797 for the details. |
The following patch fixes it for me 🎉 diff --git a/nativelib/src/main/resources/stat.c b/nativelib/src/main/resources/stat.c
index dd149fc9..3b4e3ac3 100644
--- a/nativelib/src/main/resources/stat.c
+++ b/nativelib/src/main/resources/stat.c
@@ -41,9 +41,15 @@ void scalanative_stat_init(struct stat *stat,
my_stat->st_uid = stat->st_uid;
my_stat->st_gid = stat->st_gid;
my_stat->st_size = stat->st_size;
+#ifdef __APPLE__
+ my_stat->st_atim = stat->st_atimespec;
+ my_stat->st_mtim = stat->st_mtimespec;
+ my_stat->st_ctim = stat->st_ctimespec;
+#else
my_stat->st_atim = stat->st_atim;
my_stat->st_mtim = stat->st_mtim;
my_stat->st_ctim = stat->st_ctim;
+#endif
my_stat->st_blocks = stat->st_blocks;
my_stat->st_blksize = stat->st_blksize;
my_stat->st_nlink = stat->st_nlink;
|
@avdv I couldn't see much choice but your solution - More modern POSIX has the correct implementation but it appears Apple is behind here. |
@avdv, @ekrich Thank you for the time & research. A few quick thoughts
Do either of you know if SN is supposed to be supporting Apple < OSX? If yes, I could see
Thoughts? This is Thanksgiving week in the USA. If we converge on a propose solution, I will try to edit |
Thoughts after a quick firehose education on Apple, OSX, macos, timestamps, etc.
I figure I have 39 years and 360+ days left to wander in this Wilderness.... |
OK, A path forward becomes clearer. It appears that OSX has had So I can test for AVAILABILITY. If not defined (short branch), Thoughts? Sound like a plan? |
@LeeTibbert I am not so sure we need such a robust mechanism. I'm thinking the |
@ekrich Agreed about not supporting old versions, for all the reasons you state & probably a few more. With a simple _APPLE, someone, somewhere, somewhen, will complain about this code not I try to get my intended edit in late Sunday or so, so that you and @avdv can have something |
To Everything There Is a Season (Ecclesiastes 3) The merge of PR #2087 brings the season of this PR to an end. The underlying idea is still good & useful The current direction is that There are Work in Progress PRs which depended upon the merge of this PR. If & when I can |
prepare for reworking scala-native#1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat
prepare for reworking scala-native#1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat
prepare for reworking scala-native#1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat
prepare for reworking scala-native#1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat
* use high resolution file stat fields prepare for reworking #1635: nanosecond resolution in javalib FileTime and posixlib sys/stat This commit introduces breaking changes in public api. This commit changes stat struct fields so that it can use high resolution file stat, which is available since linux kernel 2.5.48 and later. For more detail,see linux man page https://linux.die.net/man/2/stat * fix: remove wrong type declaration * fix: put scalanative timespec back * update: use statOps to access fields - improve readability and reduce making a mistake to access wrong fields - prevent stat.scala misc changes(e.g. changing field order) from spreading around codebase * minor fix: address code review * add test and inline docs * docs: mention breaking changes in next release note
This PR requires PR WIP: Provide symbol fcntl.AT_FDCWD. Requires PR #1633, will fix after that is merged. #1634, Fix 2059: Remove non-standard fcntl.close() & use proper unistd.close(). #1633, & Fix #1613: Restore the two argument fcntl.open() method. #1614. Travis CI will fail until
those PRs have been merged.
This PR fixes Issue SN only supports seconds resolution for FileTime #1610 "SN only supports seconds resolution
for FileTime". My thanks to @avdv for detecting & reporting this
issue.
Nanosecond resolutions are now supported in both javalib FileTime
and posixlib sys/stat where the underlying operating and file systems
support nanoseconds.
THIS CHANGE REQUIRES CHANGES TO EXISTING APPLICATIONS WHICH USE
TIME FIELDS IN
struct stat
. The required changes are describedin new edits to
docs/lib/posixlib
anddocs/lib/javalib
.Instant.scala was upgraded only to the point of allowing this PR.
Extensive work, beyond the scope of this PR, is needed in
java.date.time
.A unit test was added to
java/nio/file/FilesSuite.scala
toset and read a nanosecond file time. This test was designed to work
where nanosecond file times are supported and not fail where they
are not.
The test suite
java/time/InstantSuite.scala
was added to validateInstant.scala.
Documentation:
The standard changelog entry is requested.
docs/lib/javalib.rst
anddocs/lib/posixlib.rst
have each been editedto describe the changes of this PR and how to adapt existing code.
Testing:
X86_64 only . All tests pass.