From 94504a0bac335d5acfe1031a84c8f9c8b4f75ff1 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 24 Apr 2018 12:10:18 -0700 Subject: [PATCH] add option to skip special files (#15) * add option to skip special files * use stat object * check if directly, make sure we have a.stat first --- README.md | 5 +++-- index.js | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 240eb6f..4b4a8bd 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,9 @@ Options include: dereference: false, // dereference any symlinks equals: fun, // optional function to determine if two entries are the same, see below ignore: null, // optional function to ignore file paths on src or dest - dryRun: false // emit all events but don't write/del files, - keepExisting: false // whether to delete extra files in the destination that are not present in the source + dryRun: false, // emit all events but don't write/del files, + keepExisting: false, // whether to delete extra files in the destination that are not present in the source + skipSpecial: true // skip any files that are not regular files } ``` diff --git a/index.js b/index.js index d48c686..b27d7d4 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ module.exports = mirror function mirror (src, dst, opts, cb) { if (typeof opts === 'function') return mirror(src, dst, null, opts) if (!opts) opts = {} + if (opts.skipSpecial !== false) opts.skipSpecial = true var progress = new events.EventEmitter() progress.destroy = destroy @@ -89,6 +90,11 @@ function mirror (src, dst, opts, cb) { // copy to b if (a.stat && !b.stat) return put(a, b, next) + if (!a.stat.isDirectory() && opts.skipSpecial && !a.stat.isFile()) { + progress.emit('skip', a, b) + return next() + } + // check if they are the same equals(a, b, function (err, same) { if (err) throw err