ryanmcgrath / wrench-js

Recursive file operations in Node.js
MIT License
435 stars 71 forks source link

copyDirSyncRecursive removes target directory directories #23

Closed bebraw closed 12 years ago

bebraw commented 12 years ago

Hi,

Just noticed that copyDirSyncRecursive removes all directories in the given target directory. It retains files at the target so I guess this must be some kind of bug (or something to spec). I'm going to need something non-destructive myself.

ryanmcgrath commented 12 years ago

Ah, I'm uber slow to get back to this at the moment, apologies.

You can actually avoid copyDirSyncRecursive doing so, by passing in an optional parameter. If you look at the signature itself...

exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {

    if (!opts || !opts.preserve) {
        try {
            if(fs.statSync(newDirLocation).isDirectory()) exports.rmdirSyncRecursive(newDirLocation);
        } catch(e) { }
    }
    // ...
bebraw commented 12 years ago

Oh. Man, should've read the code. :)

You probably should mention about this at the README, though. It might be preferable to have it set to preserve by default to avoid accidents.

Is there some tidy way to filter source by the way? I would like to exclude certain files (ie. dotfiles + some based on name and perhaps extension) from the result.