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 truncate date #13520

Closed
buckle2000 opened this issue Jun 7, 2017 · 7 comments
Closed

fs.utimes truncate date #13520

buckle2000 opened this issue Jun 7, 2017 · 7 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@buckle2000
Copy link

buckle2000 commented Jun 7, 2017

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?

@buckle2000 buckle2000 changed the title fs.utimes truncated fs.utimes set truncated date Jun 7, 2017
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Jun 7, 2017
@buckle2000 buckle2000 changed the title fs.utimes set truncated date fs.utimes truncate date Jun 7, 2017
@duanyao
Copy link
Contributor

duanyao commented Jul 10, 2017

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.

@bnoordhuis
Copy link
Member

@refack Was this fixed by #13281?

@refack
Copy link
Contributor

refack commented Jul 10, 2017

@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

@refack
Copy link
Contributor

refack commented Jul 10, 2017

@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);

@refack
Copy link
Contributor

refack commented Jul 10, 2017

PR to improve docs #14154

@refack refack added windows Issues and PRs related to the Windows platform. wsl Issues and PRs related to the Windows Subsystem for Linux. labels Jul 22, 2017
@bnoordhuis
Copy link
Member

@refack Can this be closed?

@refack
Copy link
Contributor

refack commented Sep 29, 2017

Fixed by 64e97b2

@refack refack closed this as completed Sep 29, 2017
@refack refack added doc Issues and PRs related to the documentations. and removed wsl Issues and PRs related to the Windows Subsystem for Linux. labels Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

5 participants