Skip to content

Commit

Permalink
lib/copy: added clobber to copyFileSync()
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Mar 19, 2015
1 parent 0bed228 commit a592001
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ var mkdir = require('./mkdir')
var BUF_LENGTH = 64 * 1024
var _buff = new Buffer(BUF_LENGTH)

var copyFileSync = function (srcFile, destFile) {
var copyFileSync = function (srcFile, destFile, clobber) {
if (fs.existsSync(destFile) && !clobber)
throw Error('EEXIST')

var fdr = fs.openSync(srcFile, 'r')
var stat = fs.fstatSync(fdr)
var fdw = fs.openSync(destFile, 'w', stat.mode)
Expand Down Expand Up @@ -62,6 +65,9 @@ function copySync (src, dest, options) {
options = options || {}
options.recursive = !!options.recursive

// default to true for now
options.clobber = 'clobber' in options ? !!options.clobber : true

options.filter = options.filter || function () { return true }

var stats = options.recursive ? fs.lstatSync(src) : fs.statSync(src)
Expand All @@ -75,7 +81,7 @@ function copySync (src, dest, options) {

if (performCopy) {
if (!destFolderExists) mkdir.mkdirsSync(destFolder)
copyFileSync(src, dest)
copyFileSync(src, dest, options.clobber)
}
} else if (stats.isDirectory()) {
if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
Expand Down

0 comments on commit a592001

Please sign in to comment.