Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fix simple/test-fs-utimes.js on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky authored and ry committed Oct 12, 2011
1 parent 2b46959 commit 99757cb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/simple/test-fs-utimes.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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
});
Expand Down

4 comments on commit 99757cb

@bnoordhuis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@igorzi
Copy link

@igorzi igorzi commented on 99757cb Nov 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@isaacs isaacs commented on 99757cb Nov 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.