Skip to content

Commit

Permalink
8x faster copy
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 4, 2020
1 parent c807887 commit bff5924
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ module.exports = function(grunt) {
tally.dirs++;
} else {
grunt.verbose.writeln('Copying ' + chalk.cyan(src) + ' -> ' + chalk.cyan(dest));
grunt.file.copy(src, dest, copyOptions);
if (options.timestamp !== false) {
syncTimestamp(src, dest);
}
if (options.mode !== false) {
fs.chmodSync(dest, (options.mode === true) ? fs.lstatSync(src).mode : options.mode);
// use 8x faster copy if possible.
if (fs.copyFileSync && options.mode !== false && options.timestamp !== false && !options.process) {
fs.mkdirSync(path.dirname(dest), {recursive: true});
fs.copyFileSync(src, dest);
} else {
grunt.file.copy(src, dest, copyOptions);
if (options.timestamp !== false) {
syncTimestamp(src, dest);
}
if (options.mode !== false) {
fs.chmodSync(dest, (options.mode === true) ? fs.lstatSync(src).mode : options.mode);
}
}
tally.files++;
}
Expand Down

0 comments on commit bff5924

Please sign in to comment.