-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
utime behaviour different from MRI #4710
Comments
IIRC, JVM does not provide the same granularity of time, so this can't be fixed. |
I was expecting a difference between MRI and JVM, but it seems strange (unexpected, at least) that inside the JVM |
JRuby implements File.utime with utimes native call and timeval data structure which precision is the microsecond and not the nanosecond. We could update JRuby utime to call libc utimenstat instead of utimes. Would this still be POSIX? It would be using timespec struct instead to be on par with Ruby. We would need to create the struct and add the method in the native interface in jnr-posix lib? Test FailureIt seems the cast to integer in your snippet does not make the test fail.
Links
|
the original report seems to be resolved by (latest) 9.1.15.0 :
... for the second issue there's already a separate issue, right? any objections on closing this one? |
I am not sure this is fixed. Can you try again, line 8 without the cast to int:
|
@alexis779 you're right, noticed the jnr-posix links here - but was weird that the example passed someone from @jruby/core should take a look at your work, for reference here's the failing script : F = '/tmp/test'
File.open(F, 'w') {} # "touch" the file
mtime = File.mtime(F)
File.utime(Time.now, 0, F)
File.mtime(F).to_i == 0 or raise "mtime should be 0"
File.utime(Time.now, mtime, F)
File.mtime(F) == mtime or raise "File.mtime should be == mtime" |
Not all platforms provide this granularity of filesystem times, which is the main reason we tend to default to what the JVM provides, usually millisecond granularity at best. However we have made improvements over time to support the higher-granularity filesystem times when we can call to the appropriate native structures. For example, see 41f2bb6 which added nanosecond granularity (where supported by the platform and by jnr-posix) for atime, ctime, and mtime. @gioele Your logic for using |
FFI changes are already in a new jnr-posix PR: jnr/jnr-posix#107 In #4795 we are just calling new futimens method from POSIX Java interface. You are right if the platform does not support futimens, updating the modification time via jruby will not work anymore because futimens is not implemented in the JavaPOSIX interface. |
@alexis779 Excellent thank you! I'll see about pulling it in and utilizing it in JRuby. |
@alexis779 I see some activity on your JRuby commit for jnr-posix. I will push the release with futimes and update JRuby to use it. From there, can you put together a PR for the JRuby part, once you've confirmed it's working? |
Thanks for merging jnr-posix PR. Updated #4795 jruby PR Test
Reproduction case
Test fails. The nanosecond precision in Modify date was lost after the With the patch
Test passes. The nanosecond precision in Modify date was maintained after the Windows
JRuby Limitations
|
[#4710] nanosecond precision in utime using libc futimens
[#4710] nanosecond precision in utime using libc futimens
I've merged #4795 to master and 9.1.16.0. Thank you for your help! |
The following code works as expected in MRI, but fails in JRuby 9.1.9.0.
Found while testing the
filepath
gem via Travis-CI. The log is available at https://travis-ci.org/gioele/filepath/jobs/251546194The text was updated successfully, but these errors were encountered: