Skip to content

Commit

Permalink
Apply filter before creating parent dir in copy
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Nov 9, 2017
1 parent 9639c69 commit 8ca1074
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/copy/copy.js
Expand Up @@ -34,22 +34,25 @@ function copy (src, dest, opts, cb) {

// 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.'))
return startCopy(src, dest, opts, cb)
}

function startCopy (src, dest, opts, cb) {
if (opts.filter && !opts.filter(src, dest)) return cb()

const destParent = path.dirname(dest)
pathExists(destParent, (err, dirExists) => {
if (err) return cb(err)
if (dirExists) return getStats(src, dest, opts, cb)
if (dirExists) return startCopy(src, dest, opts, cb)
mkdirp(destParent, err => {
if (err) return cb(err)
return getStats(src, dest, opts, cb)
return startCopy(src, dest, opts, cb)
})
})
}

function startCopy (src, dest, opts, cb) {
if (opts.filter && !opts.filter(src, dest)) return cb()
return getStats(src, dest, opts, cb)
}

function getStats (src, dest, opts, cb) {
const stat = opts.dereference ? fs.stat : fs.lstat
stat(src, (err, st) => {
Expand Down

0 comments on commit 8ca1074

Please sign in to comment.