Skip to content

fs.utimes truncate date #13520

Closed
Closed

Description

@buckle2000

Version: v6.10.3
Platform: Windows 10 64-bit
Subsystem: fs
Disk format: NTFS

This issue is related to #13255 .

let fs = require('fs');
let src = 'path/to/src';
let src_stats = fs.statSync(src);
let dest = 'path/to/dest'
if (fs.existsSync(dest)) {
  fs.utimesSync(dest, src_stats.atime, src_stats.mtime);
}
let dest_stats = fs.statSync(dest);
console.log(src_stats.mtime);
console.log(dest_stats.mtime);
console.log(src_stats.mtime == dest_stats.mtime);

output:

2017-05-11T06:35:33.501Z
2017-05-11T06:35:33.000Z
false

So the millisecond part of mtime is discarded when setting the time but not when getting the time.
Why is this inconsistent?

Activity

  1. changed the title [-]fs.utimes truncated[/-] [+]fs.utimes set truncated date[/+] on Jun 7, 2017
  2. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Jun 7, 2017
  3. changed the title [-]fs.utimes set truncated date[/-] [+]fs.utimes truncate date[/+] on Jun 7, 2017
  4. duanyao commented on Jul 10, 2017

    @duanyao
    Contributor

    I confirm that this issue also happen on Linux 4.9.29, X86-64, with ext4 fs, node v6.10.2.
    The workaround is using fs.futimes{Sync} instead.

  5. bnoordhuis commented on Jul 10, 2017

    @bnoordhuis
    Member

    @refack Was this fixed by #13281?

  6. refack commented on Jul 10, 2017

    @refack
    Contributor

    @refack Was this fixed by #13281?

    I'll test, but FWIW if the issue is not in utimesSync we also have #13173 the issue is in utimes / utimesSync

  7. refack commented on Jul 10, 2017

    @refack
    Contributor

    @refack Was this fixed by #13281?

    So, fixed on windows:

    d:\code\node-cur$ node ..\4node\test-utime-truncation.js
    2017-07-10T14:20:16.103Z
    2017-07-10T14:20:16.103Z
    true
    
    d:\code\node-cur$ node -v
    v8.1.1
    

    Broken on WSL (so assuming Ubuntu)

    refael@refaelux:/mnt/d/code/node$ node ../4node/test-utime-truncation.js
    2017-07-10T14:20:16.103Z
    2017-07-10T14:20:16.000Z
    false
    refael@refaelux:/mnt/d/code/node$ node -v
    v9.0.0-nightly2017070918069523f8

    [edit]
    😕 But the docs say the times need to be integers in seconds - https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback

    test-utime-truncation.js
    let fs = require('fs');
    let src = __filename;
    let src_stats = fs.statSync(src);
    let dest = src + '2';
    if (fs.existsSync(dest)) {
      fs.utimesSync(dest, src_stats.atime, src_stats.mtime);
    }
    let dest_stats = fs.statSync(dest);
    console.log(src_stats.mtime);
    console.log(dest_stats.mtime);
    console.log(+src_stats.mtime == +dest_stats.mtime);
  8. refack commented on Jul 10, 2017

    @refack
    Contributor

    PR to improve docs #14154

  9. added
    windowsIssues and PRs related to the Windows platform.
    wslIssues and PRs related to the Windows Subsystem for Linux.
    on Jul 22, 2017
  10. bnoordhuis commented on Sep 29, 2017

    @bnoordhuis
    Member

    @refack Can this be closed?

  11. refack commented on Sep 29, 2017

    @refack
    Contributor

    Fixed by 64e97b2

  12. added
    docIssues and PRs related to Node.js documentation.
    and removed
    wslIssues and PRs related to the Windows Subsystem for Linux.
    on Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions