diff --git a/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js b/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js index 41544866..6775a4dd 100644 --- a/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js +++ b/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js @@ -5,14 +5,17 @@ const os = require('os') const path = require('path') const utimes = require('../../util/utimes') const assert = require('assert') +const nodeVersion = process.versions.node +const nodeVersionMajor = parseInt(nodeVersion.split('.')[0], 10) /* global beforeEach, afterEach, describe, it */ if (process.arch === 'ia32') console.warn('32 bit arch; skipping copySync timestamp tests') +if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copySync timestamp tests`) -const describeIf64 = process.arch === 'ia32' ? describe.skip : describe +const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe -describeIf64('copySync() - preserveTimestamps option', () => { +describeIfPractical('copySync() - preserveTimestamps option', () => { let TEST_DIR, src, dest beforeEach(done => { diff --git a/lib/copy-sync/copy-sync.js b/lib/copy-sync/copy-sync.js index edcc0dd7..c4742db8 100644 --- a/lib/copy-sync/copy-sync.js +++ b/lib/copy-sync/copy-sync.js @@ -74,7 +74,7 @@ function mayCopyFile (srcStat, src, dest, opts) { } function copyFile (srcStat, src, dest, opts) { - if (typeof fs.copyFile === 'function') { + if (typeof fs.copyFileSync === 'function') { fs.copyFileSync(src, dest) fs.chmodSync(dest, srcStat.mode) if (opts.preserveTimestamps) { @@ -100,12 +100,10 @@ function copyFileFallback (srcStat, src, dest, opts) { pos += bytesRead } + if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime) + fs.closeSync(fdr) fs.closeSync(fdw) - fs.chmodSync(dest, srcStat.mode) - if (opts.preserveTimestamps) { - return utimesSync(dest, srcStat.atime, srcStat.mtime) - } } function onDir (srcStat, src, dest, opts) {