Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fix simple/test-fs-utimes.js on windows

  • Loading branch information...
Igor Zinkovsky authored and ry committed Oct 12, 2011
1 parent 2b46959 commit 99757cbeb22d34c8365637988e16db07fc380ec8
Showing with 8 additions and 2 deletions.
  1. +8 −2 test/simple/test-fs-utimes.js
@@ -3,6 +3,8 @@ var assert = require('assert');
var util = require('util');
var fs = require('fs');

var is_windows = process.platform === 'win32';

var tests_ok = 0;
var tests_run = 0;

@@ -96,7 +98,11 @@ function runTests(atime, mtime, callback) {
expect_errno('utimes', 'foobarbaz', err, 'ENOENT');

// don't close this fd
fd = fs.openSync(__filename, 'r');
if (is_windows) {
fd = fs.openSync(__filename, 'r+');
} else {
fd = fs.openSync(__filename, 'r');
}

fs.futimes(fd, atime, mtime, function(err) {
expect_ok('futimes', fd, err, atime, mtime);
@@ -119,7 +125,7 @@ var stats = fs.statSync(__filename);

runTests(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
runTests(new Date(), new Date(), function() {
runTests(1234.5678, 1234.5678, function() {
runTests(123456.789, 123456.789, function() {
runTests(stats.mtime, stats.mtime, function() {
// done
});

4 comments on commit 99757cb

@bnoordhuis

This comment has been minimized.

Copy link
Member

replied Nov 22, 2011

@igorzi: Why do you need to open the file with r+ on Windows?

@igorzi

This comment has been minimized.

Copy link

replied Nov 30, 2011

@bnoordhuis sorry for the delay.. on Windows futimes is implemented using SetFileTime, which requires the file handle to be opened with FILE_WRITE_ATTRIBUTES access right. r maps to O_RDONLY, which doesn't get FILE_WRITE_ATTRIBUTES right. r+ maps to O_RDWR, which does get FILE_WRITE_ATTRIBUTES right. Are there any Unices that require r+ for futimes?

@bnoordhuis

This comment has been minimized.

Copy link
Member

replied Nov 30, 2011

Right, @piscisaureus told me more or less the same.

Are there any Unices that require r+ for futimes?

No. Opening the file in read-only mode is enough to update file attributes. Regular uid/gid access control still applies, of course.

@isaacs

This comment has been minimized.

Copy link

replied Nov 30, 2011

@igorzi Could you add a comment in the code explaining that, for when we forget all about this? Thanks.

Please sign in to comment.
You can’t perform that action at this time.