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

[#4710] nanosecond precision in utime using libc futimens #4795

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

alexis779
Copy link
Contributor

@alexis779 alexis779 commented Sep 23, 2017

timeval & ufiles only provide microsecond precision. Use timespec & futimens from libc to implement File.ufile, to provide nanosecond precision.

This PR is required jnr/jnr-posix#107 to be able to use the native function.

Testing

test/utime.rb

F = '/tmp/test'
mtime = File.mtime(F)

File.utime(Time.now, mtime, F)
File.mtime(F) == mtime or raise "File.mtime should be == mtime"

JRuby error

$ touch /tmp/test
$ stat /tmp/test 
  File: /tmp/test
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 430953      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  alexis)   Gid: ( 1000/  alexis)
Access: 2017-09-23 15:50:57.974453385 -0700
Modify: 2017-09-23 15:50:57.974453385 -0700
Change: 2017-09-23 15:50:57.974453385 -0700
 Birth: -
$ ruby -v
jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 OpenJDK 64-Bit Server VM 25.144-b01 on 1.8.0_144-8u144-b01-1-b01 +jit [linux-x86_64]
$ ruby test/utime.rb
RuntimeError: File.mtime should be == mtime
  <main> at test/utime.rb:6
$ stat /tmp/test 
  File: /tmp/test
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 430953      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  alexis)   Gid: ( 1000/  alexis)
Access: 2017-09-23 15:51:12.058870000 -0700
Modify: 2017-09-23 15:50:57.974453000 -0700
Change: 2017-09-23 15:51:12.062198429 -0700
 Birth: -

PR fix

$ bin/ruby -v
jruby 9.2.0.0-SNAPSHOT (2.4.1) 2017-09-23 0f9c2a3 OpenJDK 64-Bit Server VM 25.144-b01 on 1.8.0_144-8u144-b01-1-b01 +jit [linux-x86_64]
$ ruby test/utime.rb
$

@enebo
Copy link
Member

enebo commented Jan 10, 2018

@alexis779 I updated this to remove the conflicts but then realized your jnr-posix PR never got accepted. I asked about Windows support which will need to work or at least we will need to work around it not existing on that platform (although I did not check...they do have some of these methods on windows sometimes).

@headius headius merged commit 064e235 into jruby:master Feb 13, 2018
headius added a commit that referenced this pull request Feb 13, 2018
[#4710] nanosecond precision in utime using libc futimens
@headius headius added this to the JRuby 9.1.16.0 milestone Feb 13, 2018
@headius
Copy link
Member

headius commented Feb 13, 2018

Merged to master and 9.1.16.0.

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

Successfully merging this pull request may close these issues.

None yet

3 participants