Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix streams initialization in copyFileFallback #516

Merged
merged 1 commit into from Nov 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/copy/copy.js
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