Skip to content

Commit

Permalink
lib/copy/copy.js: fix module loading syntax for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Oct 19, 2017
1 parent 79fe4d3 commit d9d0e74
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/copy/copy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const fs = require('graceful-fs')
const {resolve, join, dirname, basename, sep} = require('path')
const path = require('path')
const mkdirp = require('../mkdirs').mkdirs
const pathExists = require('../path-exists').pathExists
const utimes = require('../util/utimes').utimesMillis
Expand Down Expand Up @@ -29,13 +29,13 @@ function copy (src, dest, opts, cb) {
see https://github.com/jprichardson/node-fs-extra/issues/269`)
}

src = resolve(src)
dest = resolve(dest)
src = path.resolve(src)
dest = path.resolve(dest)

// don't allow src and dest to be the same
if (src === dest) return cb(new Error('Source and destination must not be the same.'))

const destParent = dirname(dest)
const destParent = path.dirname(dest)
pathExists(destParent, (err, dirExists) => {
if (err) return cb(err)
if (dirExists) return startCopy(src, dest, opts, cb)
Expand Down Expand Up @@ -166,7 +166,7 @@ function cpDir (src, dest, opts, cb) {
function cpDirItems (items, src, dest, opts, cb) {
const item = items.pop()
if (!item) return cb()
startCopy(join(src, item), join(dest, item), opts, err => {
startCopy(path.join(src, item), path.join(dest, item), opts, err => {
if (err) return cb(err)
return cpDirItems(items, src, dest, opts, cb)
})
Expand All @@ -177,7 +177,7 @@ function onLink (src, dest, opts, cb) {
if (err) return cb(err)

if (opts.dereference) {
resolvedSrcPath = resolve(process.cwd(), resolvedSrcPath)
resolvedSrcPath = path.resolve(process.cwd(), resolvedSrcPath)
}

checkDest(dest, (err, resolvedDestPath) => {
Expand All @@ -189,7 +189,7 @@ function onLink (src, dest, opts, cb) {
return fs.symlink(resolvedSrcPath, dest, cb)
} else {
if (opts.dereference) {
resolvedDestPath = resolve(process.cwd(), resolvedDestPath)
resolvedDestPath = path.resolve(process.cwd(), resolvedDestPath)
}
if (resolvedDestPath === resolvedSrcPath) return cb()

Expand Down Expand Up @@ -233,11 +233,11 @@ function checkDest (dest, cb) {
// return true if dest is a subdir of src, otherwise false.
// extract dest base dir and check if that is the same as src basename
function isSrcSubdir (src, dest) {
const baseDir = dest.split(dirname(src) + sep)[1]
const baseDir = dest.split(path.dirname(src) + path.sep)[1]
if (baseDir) {
const destBasename = baseDir.split(sep)[0]
const destBasename = baseDir.split(path.sep)[0]
if (destBasename) {
return src !== dest && dest.indexOf(src) > -1 && destBasename === basename(src)
return src !== dest && dest.indexOf(src) > -1 && destBasename === path.basename(src)
}
return false
}
Expand Down

0 comments on commit d9d0e74

Please sign in to comment.