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

fs.copy, handle e.g. EBUSY #511

Closed
wants to merge 2 commits into from
Closed
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
44 changes: 24 additions & 20 deletions lib/copy/ncp.js
Expand Up @@ -96,30 +96,34 @@ function ncp (source, dest, options, callback) {

function copyFile (file, target) {
var readStream = fs.createReadStream(file.name)
var writeStream = fs.createWriteStream(target, { mode: file.mode })

readStream.on('error', onError)
writeStream.on('error', onError)

if (transform) {
transform(readStream, writeStream, file)
} else {
writeStream.on('open', function () {
readStream.pipe(writeStream)
})
}
readStream.once('open', function () {
var writeStream = fs.createWriteStream(target, { mode: file.mode })

writeStream.once('close', function () {
fs.chmod(target, file.mode, function (err) {
if (err) return onError(err)
if (preserveTimestamps) {
utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
if (err) return onError(err)
return doneOne()
})
} else {
doneOne()
}
writeStream.on('error', onError)

if (transform) {
transform(readStream, writeStream, file)
} else {
writeStream.on('open', function () {
readStream.pipe(writeStream)
})
}

writeStream.once('close', function () {
fs.chmod(target, file.mode, function (err) {
if (err) return onError(err)
if (preserveTimestamps) {
utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
if (err) return onError(err)
return doneOne()
})
} else {
doneOne()
}
})
})
})
}
Expand Down