diff --git a/tasks/copy.js b/tasks/copy.js index c989de3..3b1c479 100644 --- a/tasks/copy.js +++ b/tasks/copy.js @@ -14,6 +14,7 @@ module.exports = function(grunt) { var fs = require('fs'); var chalk = require('chalk'); var fileSyncCmp = require('file-sync-cmp'); + var isWindows = /^win/.test(process.platform); grunt.registerMultiTask('copy', 'Copy files.', function() { @@ -102,7 +103,7 @@ module.exports = function(grunt) { }; var unixifyPath = function(filepath) { - if (process.platform === 'win32') { + if (isWindows) { return filepath.replace(/\\/g, '/'); } else { return filepath; @@ -119,6 +120,8 @@ module.exports = function(grunt) { return; } - fs.utimesSync(dest, stat.atime, stat.mtime); + var fd = fs.openSync(dest, isWindows ? 'r+' : 'r'); + fs.futimesSync(fd, stat.atime, stat.mtime); + fs.closeSync(fd); }; }; diff --git a/test/copy_test.js b/test/copy_test.js index cde5154..ce8b30b 100644 --- a/test/copy_test.js +++ b/test/copy_test.js @@ -2,6 +2,7 @@ var grunt = require('grunt'); var fs = require('fs'); +var isWindows = /^win/.test(process.platform); exports.copy = { main: function(test) { @@ -64,8 +65,10 @@ exports.copy = { modeDir: function(test) { test.expect(2); - test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder').mode.toString(8).slice(-3), '777'); - test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder/sub_folder').mode.toString(8).slice(-3), '777'); + // on windows DIRs do not have 'executable' flag, see: https://github.com/nodejs/node/blob/master/deps/uv/src/win/fs.c#L1064 + var expectedMode = isWindows ? '666' : '777'; + test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder').mode.toString(8).slice(-3), expectedMode); + test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder/sub_folder').mode.toString(8).slice(-3), expectedMode); test.done(); },