From 987f062e237d2cc9a36c38e0ab6c74d580d485ff Mon Sep 17 00:00:00 2001 From: Gosha Arinich Date: Wed, 4 May 2016 15:32:01 +0300 Subject: [PATCH] Emit a warning when a destination file exists and won't be overwritten --- README.md | 2 ++ lib/ncp.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 9480032..90af3a8 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,6 @@ You can also call ncp like `ncp(source, destination, options, callback)`. * `options.errs` - stream. If `options.stopOnErr` is `false`, a stream can be provided, and errors will be written to this stream. + * `options.warns` - stream of warnings (like a destination file already existing when clobber=false). + Please open an issue if any bugs arise. As always, I accept (working) pull requests, and refunds are available at `/dev/null`. diff --git a/lib/ncp.js b/lib/ncp.js index 96eed47..7591c4d 100644 --- a/lib/ncp.js +++ b/lib/ncp.js @@ -94,6 +94,16 @@ function ncp (source, dest, options, callback) { rmFile(target, function () { copyFile(file, target); }); + } else { + var warns = options.warns; + var warn = "destination file '" + target + "' already exists, skipping"; + if (warns) { + if (typeof warns.write === 'undefined') { + warns.push(warn); + } else { + warns.write(warn); + } + } } if (modified) { var stat = dereference ? fs.stat : fs.lstat;