Skip to content

fs: consider NaN/Infinity in toUnixTimestamp - #2387

Closed
yorkie wants to merge 1 commit into
nodejs:masterfrom
yorkie:fix/fs
Closed

fs: consider NaN/Infinity in toUnixTimestamp#2387
yorkie wants to merge 1 commit into
nodejs:masterfrom
yorkie:fix/fs

Conversation

@yorkie

Copy link
Copy Markdown
Contributor

We might should follow the rule of linux:

If times is NULL, then the access and modification times of the file are set to the current time.

ref: http://linux.die.net/man/2/utime

@mscdexmscdex added the fs Issues and PRs related to the fs subsystem / file system. label Aug 15, 2015
@mscdex

Copy link
Copy Markdown
Contributor

Why not replace both checks with !isFinite()?

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Oh, I absolutely this function, let me use and test it, thanks for the tip

@mscdexmscdex added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 15, 2015
@yorkie

Copy link
Copy Markdown
ContributorAuthor

Fixed, thank you Brian

@mscdex

Copy link
Copy Markdown
Contributor

I meant replace both conditions, like simply:

if(!isFinite(time)){

since !isFinite(NaN) === true

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Fixed, thank you

Comment threadtest/parallel/test-fs-utimes.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly to do here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it should be "done"

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Corrected, thanks @thefourtheye

Comment threadlib/fs.js Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use Number.isFinite() instead of isFinite():

In comparison to the global isFinite() function, this method doesn't forcibly convert the parameter to a number. This means only values of the type number, that are also finite, return true.

Doesn't matter here, but good for consistency.

@yorkie

Copy link
Copy Markdown
ContributorAuthor

After reading some docs about the difference at MDN and ECMA spec, I changed it to use the Number.isFinite is better than that global function. Thanks @sindresorhus

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Any feedback from core team?

@trevnorris

Copy link
Copy Markdown
Contributor

LGTM

@thefourtheye

Copy link
Copy Markdown
Contributor

Hmmm.

  1. what about the negative numbers?
  2. Also, we should mention this behaviour in the docs as well, I think.

@yorkie

Copy link
Copy Markdown
ContributorAuthor

what about the negative numbers?

I have no idea about the negative, because the linux manual didn't mention this, so I have the following proposals:

  • Treat it as NULL and set the date to Date.now()
  • Date.now() + time means minus the absolute value
  • Do nothing

Also, we should mention this behaviour in the docs as well, I think.

I will document this either after getting the answer of the above from @thefourtheye or other Node.js team member. Thank you :)

@yorkie

Copy link
Copy Markdown
ContributorAuthor

any words? @thefourtheye

@yorkie

Copy link
Copy Markdown
ContributorAuthor

How is this pr going? @thefourtheye did ignore my questions and proposals again, I don't know what happened :(

@trevnorris

Copy link
Copy Markdown
Contributor

@yorkie Might be outside the scope of this PR, but is there utility in accepting strings? The check would basically be:

if(typeoftime==='string'&&+time==time){return+time;}

I'm cool w/ the change if CI is happy.

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Hey @trevnorris I Added your suggestion at this PR, but I still care about strict mode and source code confusion in using the operator ==.

Mainly, the unit test is pass on my side :)

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Added few document as well, but I have not yet got any response about minus value, so I will just keep the current logic.

@thefourtheye

Copy link
Copy Markdown
Contributor

@yorkie I am really sorry about the delay. I finally got some time to test this. The value of -1 for atime and mtime seems to reset the times to UNIX Epoch time, in my Ubuntu box.

Comment threaddoc/api/fs.markdown Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If

@yorkie

Copy link
Copy Markdown
ContributorAuthor

It's fine @thefourtheye

reset the times to UNIX Epoch time

Do you have some document about this or someone from nodejs team tell me what should I do, or I think set to Unix Epoch is not still the best solution.

@trevnorris

Copy link
Copy Markdown
Contributor

@yorkie Thanks. Only reason I suggest using +val == val is because it's the only single operation to check for both stringified hex and floating point values.

@thefourtheye

Copy link
Copy Markdown
Contributor

@yorkie I searched for documentations but I couldn't find any. I found that by running

constfs=require('fs');console.error(fs.statSync('Test.py'));fs.utimesSync('Test.py',-1,-1);console.error(fs.statSync('Test.py'));

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Thanks for your work @thefourtheye, I will follow your running result at first :)

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Updated, now the minus number and other Date.now() has been set to corresponding Epoch timestamp, @thefourtheye could you please review again, thank you :)

@thefourtheye

Copy link
Copy Markdown
Contributor

@yorkie Ah, lets get some confirmation about the negative values. @bnoordhuis any idea?

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Of course, and I will document something after that :)

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Ping @bnoordhuis

@yorkie

Copy link
Copy Markdown
ContributorAuthor

@orangemocha so the thing that I should or can do is reword the title and push again?

Comment threadtest/parallel/test-fs-utimes.js Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter would break at this line? @Fishrock123

@orangemocha

Copy link
Copy Markdown
Contributor

so the thing that I should or can do is reword the title and push again?

@yorke : yes!

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Yes, sir. I will fix the line 131 as well :)

@orangemocha

Copy link
Copy Markdown
Contributor

@yorkie : or, if you added those tests in the first place, you could also do an interactive rebase and change your commits to simply not add them.

@yorkie

Copy link
Copy Markdown
ContributorAuthor

Ok, I did squash all commits then could someone run the CI again, thanks for your helps :)

@orangemocha

Copy link
Copy Markdown
Contributor

@yorkie

Copy link
Copy Markdown
ContributorAuthor

The test seems to be suspended by ARM at https://ci.nodejs.org/job/node-test-commit-arm/634/console, anything that I can help to fix?

@trevnorris

Copy link
Copy Markdown
Contributor

@yorkie Just took a really long time to finish. Everything looks green now.

trevnorris pushed a commit that referenced this pull request Sep 14, 2015
PR-URL: #2387
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@trevnorris

Copy link
Copy Markdown
Contributor

Landed on 1f842c2 with column change in doc.

@Fishrock123

Copy link
Copy Markdown
Contributor

To clarify, this is indeed a breaking change?

@yorkie
yorkie deleted the fix/fs branch September 15, 2015 04:27
@yorkie

Copy link
Copy Markdown
ContributorAuthor

Thanks @trevnorris

To clarify, this is indeed a breaking change?

Shouldn't, I guess few modules use Nan or Infinity internally, and in my opinion this seems to be a bug fix?

@rvaggrvagg mentioned this pull request Sep 15, 2015
@trevnorris

Copy link
Copy Markdown
Contributor

@Fishrock123 I'd say this is a bug-fix. This simply makes previously undefined behavior defined.

@Fishrock123Fishrock123 removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 15, 2015
Fishrock123 pushed a commit that referenced this pull request Sep 15, 2015
PR-URL: #2387
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@Fishrock123Fishrock123 mentioned this pull request Sep 15, 2015
7 tasks
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Sep 17, 2015
Notable changes:
* buffer:
- Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) nodejs#2866.
- `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) nodejs#2777.
* fs:
- `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) nodejs#2387.
- `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) nodejs#2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) nodejs#2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) nodejs#2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) nodejs#2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) nodejs#2870.
- This fixes a previously known bug where some computed object shorthand properties did not work correctly (nodejs#2507).
Refs: nodejs#2844
PR-URL: nodejs#2889
Fishrock123 added a commit that referenced this pull request Sep 17, 2015
Notable changes:
* buffer:
- Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) #2866.
- `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) #2777.
* fs:
- `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) #2387.
- `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) #2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) #2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) #2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) #2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) #2870.
- This fixes a previously known bug where some computed object shorthand properties did not work correctly (#2507).
Refs: #2844
PR-URL: #2889
@rvaggrvagg mentioned this pull request Sep 22, 2015
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fsIssues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@yorkie@mscdex@trevnorris@thefourtheye@bnoordhuis@ronkorving@Fishrock123@orangemocha@sindresorhus