From c59e0a6e2e22f7c72ff970858cfe7f5201d24a20 Mon Sep 17 00:00:00 2001 From: Mani Maghsoudlou Date: Thu, 9 Nov 2017 11:09:32 -0800 Subject: [PATCH] Fix streams initialization in copyFileFallback (introduced by @unkelpehr) --- lib/copy/copy.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/copy/copy.js b/lib/copy/copy.js index b0e06cf8..76aaa23c 100644 --- a/lib/copy/copy.js +++ b/lib/copy/copy.js @@ -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) { @@ -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)) {