Node: `fs.utimes` doesn't support `number` or `string` on Windows

Created on 4 May 2020  ·  5Comments  ·  Source: nodejs/node

  • Version: v13.14.0 (unable to install v14 on windows 7)
  • Platform: Microsoft Windows Server 2019 (GH Actions Windows CI) & 32 bit Windows 7
  • Subsystem: fs

What steps will reproduce the bug?

const fs = require('fs');

fs.utimesSync(__filename, Date.now(), Date.now());
const fs = require('fs');

fs.utimesSync(__filename, Date.now().toString(), Date.now().toString());

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

It should work same as Linux and Mac

What do you see instead?

  ● does not re-run tests when only access time is modified

    EINVAL: invalid argument, utime 'C:\Users\RUNNER~1\AppData\Local\Temp\watch_mode_no_access\foo.js'

      61 |   const modulePath = path.join(DIR, 'foo.js');
      62 |   const stat = fs.lstatSync(modulePath);
    > 63 |   fs.utimesSync(modulePath, stat.atime.getTime(), stat.mtime.getTime());
         |      ^
      64 | 
      65 |   await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 2);
      66 | 

      at Object.utimesSync (e2e/__tests__/watchModeNoAccess.test.ts:63:6)

That's from this CI run, where the same test passes on both Linux and Mac: https://github.com/facebook/jest/runs/641141754

Additional information

According to the docs, utimes can take number | string | Date: https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback. Seems like Windows only supports Date?

This is the same as #5561.

All 5 comments

Seems like Windows only supports Date?

No, but you're passing numbers that are probably out of range for the underlying file system.

Date.now() returns the time in milliseconds but fs.utimesSync() takes timestamps in seconds. You need to divide by 1,000.

Oh! Hah, would you look at that 😅 That's not mentioned in the docs, although I guess most people calling these APIs know that already?

Would it be possible for utimes to throw if number passed in is way into the future? Might be valid tho.

The documentation could be clearer on the units used, I agree. Do you want to send a PR for that?

Would it be possible for utimes to throw if number passed in is way into the future?

I don't think so. There's no real way to know what the supported range is until you try it.

@bnoordhuis quick try (or as quick as GitHub's laggy web editor allows) here: #33230

Closed by above PR

Was this page helpful?
0 / 5 - 0 ratings