Skip to content

Commit

Permalink
Improve code quality (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn authored Mar 15, 2021
1 parent 1625838 commit 7498c9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/copy-sync/copy-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ function setDestTimestamps (src, dest) {
}

function onDir (srcStat, destStat, src, dest, opts) {
if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
if (destStat && !destStat.isDirectory()) {
if (destStat) {
if (destStat.isDirectory()) {
return copyDir(src, dest, opts)
}
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
}
return copyDir(src, dest, opts)
return mkDirAndCopy(srcStat.mode, src, dest, opts)
}

function mkDirAndCopy (srcMode, src, dest, opts) {
Expand Down
8 changes: 5 additions & 3 deletions lib/copy/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ function setDestTimestamps (src, dest, cb) {
}

function onDir (srcStat, destStat, src, dest, opts, cb) {
if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts, cb)
if (destStat && !destStat.isDirectory()) {
if (destStat) {
if (destStat.isDirectory()) {
return copyDir(src, dest, opts, cb)
}
return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
}
return copyDir(src, dest, opts, cb)
return mkDirAndCopy(srcStat.mode, src, dest, opts, cb)
}

function mkDirAndCopy (srcMode, src, dest, opts, cb) {
Expand Down

0 comments on commit 7498c9c

Please sign in to comment.