Skip to content

FIX properly extract millis from the nsec part of timespec#58

Open
zuzkins wants to merge 1 commit intomafintosh:masterfrom
zuzkins:fix-bindings_get_date-ms
Open

FIX properly extract millis from the nsec part of timespec#58
zuzkins wants to merge 1 commit intomafintosh:masterfrom
zuzkins:fix-bindings_get_date-ms

Conversation

@zuzkins
Copy link
Copy Markdown

@zuzkins zuzkins commented Aug 16, 2017

There is currently a problem with the function bindings_get_date, in that it does not compute the ms part of the timestamp correctly.
The ns part of timespec should be divided by 1 000 000 rather than 1 000 as it is the case right now.

This problem manifests itself when implementing utimens function:

I have debug on when mounting my FS through OSX FUSE and when I touch a file this is the logged output:

utimens /f.txt 1502873454.867636000 1502873454.867636000

But when I log the arguments my implementation is given:

utimens (/f.txt, Wed Aug 16 2017 11:05:21 GMT+0200 (CEST), Wed Aug 16 2017 11:05:21 GMT+0200 (CEST))

Those are few minutes off (they are shifted in to the future). Correct timestamp is new Date(1502873454.867636000 * 1000) => Wed Aug 16 2017 10:50:54 GMT+0200 (CEST). Right now the millisecond part is added together with seconds and nanoseconds are used instead of millis.

This pull request fixes mentioned problem. I have no idea how to test this other than manually:

OSX FUSE log:

utimens /f.txt 1502873614.070006000 1502873614.070006000

After fixing it locally, my app logs:

utimens (/f.txt, Wed Aug 16 2017 10:53:34 GMT+0200 (CEST), Wed Aug 16 2017 10:53:34 GMT+0200 (CEST))

Which is what is expected: new Date(1502873614.070006000 * 1000) => Wed Aug 16 2017 10:53:34 GMT+0200 (CEST)

I have also looked at the function bindings_set_date, but it seems to me, that it is implemented correctly.

Thank you for your effort you put into fuse-bindings!

nsec holds nanoseconds, so we need to divide it by 10^6 to get
milliseconds back.
@sam0x17
Copy link
Copy Markdown
Contributor

sam0x17 commented Aug 17, 2017

this explains the behavior I was witnessing a few months ago -- good catch!

@sam0x17
Copy link
Copy Markdown
Contributor

sam0x17 commented Aug 19, 2017

@mafintosh this looks ready to merge

frank-dspeed added a commit to direktspeed/node-fuse-bindings that referenced this pull request Nov 24, 2019
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.

2 participants