Skip to content
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

File.mtime doesn't return milliseconds #4520

Closed
AlexWayfer opened this issue Mar 2, 2017 · 11 comments
Closed

File.mtime doesn't return milliseconds #4520

AlexWayfer opened this issue Mar 2, 2017 · 11 comments

Comments

@AlexWayfer
Copy link

@AlexWayfer AlexWayfer commented Mar 2, 2017

Environment

  • JRuby version is 9.1.7.0 (and older)
  • ArchLinux, Kernel version is 4.9.11
  • Ruby version manager is rbenv

Expected Behavior

File.mtime returns Time with milliseconds:

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

$ ruby -e "puts File.mtime('README.md').to_f"
1488443688.4152856

Actual Behavior

File.mtime returns Time without milliseconds:

$ ruby -v
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [linux-x86_64]

$ ruby -e "puts File.mtime('README.md').to_f"
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
1488443688.0
@AlexWayfer
Copy link
Author

@AlexWayfer AlexWayfer commented Mar 6, 2017

@harshvardhansharma We cannot bypass some limitations of file systems. But this should work on file systems that allow, especially where MRI works.

@harshvardhansharma
Copy link

@harshvardhansharma harshvardhansharma commented Mar 6, 2017

@AlexWayfer, right and seems to be working on a machine with MRI interpreter, will try with jRuby one and see how it can be fixed.
Do you have any other thoughts on this?

@AlexWayfer
Copy link
Author

@AlexWayfer AlexWayfer commented Mar 6, 2017

@harshvardhansharma I found this: #4393 and #1951

But they are not about files.

I think it's a flaw in JRuby, but can't say for sure, because not worked with him closely.

@headius
Copy link
Member

@headius headius commented Mar 6, 2017

@harshvardhansharma Thanks for the investigation on this one! It appears that in order to support this we would need to conditionally access the newer st_mtim etc timespec fields on the stat struct. This needs to be done in https://github.com/jnr/jnr-posix before we can use it in JRuby.

@headius
Copy link
Member

@headius headius commented Mar 6, 2017

Good news! It looks like we may have the nsec fields mapped already in jnr-posix. I'll see if I can wire them up.

@headius
Copy link
Member

@headius headius commented Mar 6, 2017

And more good news...as of Java 7, the "NIO 2" file APIs also appear to support nsec resolution. It may be possible to expose them without tying jnr-posix to Java 7, but I'm just going to wire it up for native UNIX stats for now.

@headius
Copy link
Member

@headius headius commented Mar 6, 2017

Someone want to contribute a spec to https://github.com/ruby/spec for this behavior? I don't see any existing stat a/c/mtime nanosecond specs in there and we don't want this to get missed.

AlexWayfer added a commit to AlexWayfer/spec that referenced this issue Mar 6, 2017
Reference: jruby/jruby#4520 (comment)

Three attemps to avoid zero in these values with small sleep (if failed).

And some code refactoring.
AlexWayfer added a commit to AlexWayfer/spec that referenced this issue Mar 6, 2017
Reference: jruby/jruby#4520 (comment)

Three attemps to avoid zero in these values with small sleep (if failed).

And some code refactoring.
@AlexWayfer
Copy link
Author

@AlexWayfer AlexWayfer commented Mar 6, 2017

@headius I'm trying!

AlexWayfer added a commit to AlexWayfer/spec that referenced this issue Mar 7, 2017
Reference: jruby/jruby#4520 (comment)

Three attemps to avoid zero in these values with small sleep (if failed).

And some code refactoring.
eregon added a commit to ruby/spec that referenced this issue Mar 7, 2017
Reference: jruby/jruby#4520 (comment)

Three attemps to avoid zero in these values with small sleep (if failed).

And some code refactoring.
AlexWayfer added a commit to AlexWayfer/spec that referenced this issue Mar 7, 2017
Reference: jruby/jruby#4520 (comment)

Three attemps to avoid zero in these values with small sleep (if failed).

And some code refactoring.
@AlexWayfer
Copy link
Author

@AlexWayfer AlexWayfer commented Mar 7, 2017

And done!

@headius
Copy link
Member

@headius headius commented Mar 9, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.