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

regression: fs.utimes/futimes for dates before unix epoch #14017

Closed
isaacs opened this issue Jun 30, 2017 · 7 comments
Closed

regression: fs.utimes/futimes for dates before unix epoch #14017

isaacs opened this issue Jun 30, 2017 · 7 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.

Comments

@isaacs
Copy link
Contributor

isaacs commented Jun 30, 2017

As of Node v4, fs.utimes and fs.utimes are truncating the atime and mtime values to a positive integer.

This is incorrect, and makes it impossible to set atime and mtime values before 1970-01-01T00:00:00.000Z without creating a Date object.

It looks like this is the culprit:

function toUnixTimestamp(time) {
  // eslint-disable-next-line eqeqeq
  if (typeof time === 'string' && +time == time) {
    return +time;
  }
  if (Number.isFinite(time)) {
    if (time < 0) {
      return Date.now() / 1000;
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Jul 1, 2017
@MylesBorins
Copy link
Contributor

@isaacs is this recently introduced in v4.8.3? Is there an earlier version of v4.x where this is not happening?

@TimothyGu
Copy link
Member

TimothyGu commented Jul 4, 2017

It was introduced in #2387 (specifically in #2387 (comment)), backported to version 4.1.0. In other words, only version 4.0.0 in the v4.x branch is not affected by the bug.

@gireeshpunathil
Copy link
Member

Was this fixed through #15680 ? Given 4.x entering EOL, this looks like a close candidate?
/cc @refack @lpinca

@BridgeAR
Copy link
Member

@gireeshpunathil that was a doc update about Infinity and NaN. Are you certain you referenced the correct PR? #15680 is independent from this issue as far as I can tell.

@gireeshpunathil
Copy link
Member

probably not - I was just following the linked references.

@kevintab95
Copy link
Contributor

An observation: On specifying a negative timestamp as a string for values before 1970-01-01T00:00:00.000Z the atime and utime were modified correctly (https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback).

> fs.utimes('random.txt','-9999999999.0','-9999999999.0', function(){})
>.exit

$ stat -x random.txt 
  File: "random.txt"
  Size: 0            FileType: Regular File
Device: 1,4   Inode: 69235639    Links: 1
Access: Mon Feb 10 12:06:41 1653
Modify: Mon Feb 10 12:06:41 1653
Change: Fri Oct  5 01:30:49 2018

Should we document this or figure out a way to fix it? Thanks.

@Fishrock123
Copy link
Contributor

I also cannot reproduce. The example above works fine on node master so I guess it was fixed some time since 4.x. This won't be fixed in 4.x, of course, since that branch has been sunset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.
Projects
None yet
Development

No branches or pull requests

9 participants