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

fs.utimes doesn't support number or string on Windows #33227

Closed
SimenB opened this issue May 4, 2020 · 5 comments
Closed

fs.utimes doesn't support number or string on Windows #33227

SimenB opened this issue May 4, 2020 · 5 comments

Comments

@SimenB
Copy link
Member

SimenB commented May 4, 2020

  • 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.

@SimenB SimenB changed the title fs.utimes doesn't support number on Windows fs.utimes doesn't support number or string on Windows May 4, 2020
@bnoordhuis
Copy link
Member

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.

@SimenB
Copy link
Member Author

SimenB commented May 4, 2020

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.

@bnoordhuis
Copy link
Member

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.

@SimenB
Copy link
Member Author

SimenB commented May 4, 2020

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

@SimenB
Copy link
Member Author

SimenB commented May 8, 2020

Closed by above PR

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 a pull request may close this issue.

2 participants