Skip to content

Commit

Permalink
Skip copySync preserveTimestamp tests on older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Nov 18, 2017
1 parent 5d1f2d3 commit 5bdbdc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-preserve-time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
8 changes: 3 additions & 5 deletions lib/copy-sync/copy-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 5bdbdc4

Please sign in to comment.