Skip to content

Commit

Permalink
Fix streams initialization in copyFileFallback (introduced by @unkelpehr
Browse files Browse the repository at this point in the history
)
  • Loading branch information
manidlou committed Nov 9, 2017
1 parent 603b8bb commit c59e0a6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/copy/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ function copyFile (srcStat, src, dest, opts, cb) {

function copyFileFallback (srcStat, src, dest, opts, cb) {
const rs = fs.createReadStream(src)
const ws = fs.createWriteStream(dest, { mode: srcStat.mode })

rs.on('error', err => cb(err))
ws.on('error', err => cb(err))

ws.on('open', () => rs.pipe(ws))
.once('close', () => setDestModeAndTimestamps(srcStat, dest, opts, cb))
.once('open', () => {
const ws = fs.createWriteStream(dest, { mode: srcStat.mode })
ws.on('error', err => cb(err))
.on('open', () => rs.pipe(ws))
.once('close', () => setDestModeAndTimestamps(srcStat, dest, opts, cb))
})
}

function setDestModeAndTimestamps (srcStat, dest, opts, cb) {
Expand Down Expand Up @@ -198,8 +198,8 @@ function onLink (src, dest, opts, cb) {
if (resolvedDestPath === resolvedSrcPath) return cb()

// prevent copy if src is a subdir of dest since unlinking
// dest in this case results in removing src contents
// and therefore a broken symlink will be created.
// dest in this case would result in removing src contents
// and therefore a broken symlink would be created.
fs.stat(dest, (err, st) => {
if (err) return cb(err)
if (st.isDirectory() && isSrcSubdir(resolvedDestPath, resolvedSrcPath)) {
Expand Down

0 comments on commit c59e0a6

Please sign in to comment.