Socket
Socket
Sign inDemoInstall

wrench

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrench - npm Package Compare versions

Comparing version 1.4.4 to 1.5.0

64

lib/wrench.js

@@ -74,11 +74,12 @@ /* wrench.js

function readdirRecursive(curDir) {
var files = [],
curFiles,
nextDirs,
prependcurDir = function(fname){
return _path.join(curDir, fname);
};
var prependcurDir = function(fname){
return _path.join(curDir, fname);
};
waitCount++;
fs.readdir(curDir, function(e, curFiles) {
if (e) {
fn(e);
return;
}
waitCount--;

@@ -163,3 +164,3 @@

* Synchronous function, which blocks things until it's done. If you need/want to do this in
* an Asynchronous manner, look at wrench.copyDirRecursively() below.
* an Asynchronous manner, look at wrench.copyDirRecursively() below. Specify forceDelete to force directory overwrite.
*

@@ -169,7 +170,11 @@ * Note: Directories should be passed to this function without a trailing slash.

exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
if (!opts || !opts.preserve) {
try {
if(fs.statSync(newDirLocation).isDirectory()) exports.rmdirSyncRecursive(newDirLocation);
} catch(e) { }
}
try {
if(fs.statSync(newDirLocation).isDirectory()) {
if(typeof opts !== 'undefined' && opts.forceDelete) {
exports.rmdirSyncRecursive(newDirLocation);
} else {
return new Error('You are trying to delete a directory that already exists. Specify forceDelete in the opts argument to override this. Bailing~');
}
}
} catch(e) { }

@@ -289,5 +294,10 @@ /* Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */

*/
exports.rmdirRecursive = function rmdirRecursive(dir, clbk){
exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
fs.readdir(dir, function(err, files){
if (err) return clbk(err);
if(err && typeof failSilent === 'boolean' && !failSilent)
return clbk(err);
if(typof failSilent === 'function')
clbk = failSilent;
(function rmFile(err){

@@ -312,15 +322,23 @@ if (err) return clbk(err);

/* wrench.copyDirRecursive("directory_to_copy", "new_location", callback);
/* wrench.copyDirRecursive("directory_to_copy", "new_location", {forceDelete: bool}, callback);
*
* Recursively dives through a directory and moves all its files to a new
* location.
* location. Specify forceDelete to force directory overwrite.
*
* Note: Directories should be passed to this function without a trailing slash.
*/
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, clbk) {
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
fs.stat(newDir, function(err, newDirStat){
if (!err) return exports.rmdirRecursive(newDir, function(err){
copyDirRecursive(srcDir, newDir, clbk);
});
if(!err) {
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
return exports.rmdirRecursive(newDir, function(err){
copyDirRecursive.apply(this, arguments);
});
else
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
}
if(typeof opts === 'function')
clbk = opts;
fs.stat(srcDir, function(err, srcDirStat){

@@ -337,3 +355,3 @@ if (err) return clbk(err);

if (filename === null || typeof filename == 'undefined')
return clbk();
return clbk(null);

@@ -419,3 +437,3 @@ var file = srcDir+'/'+filename,

if(this.buffer.indexOf("\n") > -1) return true;
if(this.buffer.indexOf("\n") > -1 || this.buffer.length !== 0) return true;
return false;

@@ -426,3 +444,3 @@ },

var lineEnd = this.buffer.indexOf("\n"),
result = this.buffer.substring(0, lineEnd);
result = this.buffer.substring(0, lineEnd ? lineEnd : this.buffer.length);

@@ -429,0 +447,0 @@ this.buffer = this.buffer.substring(result.length + 1, this.buffer.length);

{
"name": "wrench",
"description": "Recursive filesystem (and other) operations that Node *should* have.",
"version": "1.4.4",
"version": "1.5.0",
"author": "Ryan McGrath <ryan@venodesigns.net>",

@@ -6,0 +6,0 @@

@@ -41,3 +41,10 @@ wrench.js - Recursive file operations in Node.js

// Deep-copy an existing directory
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up');
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
forceDelete: bool, // Whether to overwrite existing directory or not
excludeHiddenUnix: bool, // Whether to copy hidden Unix files or not (preceding .)
preserveFiles: bool, // If we're overwriting something and the file already exists, keep the existing
inflateSymlinks: bool, // Whether to follow symlinks or not when copying files
filter: regexp, // A filter to match files against; if matches, do nothing (exclude).
whitelist: bool, // if true every file or directory which doesn't match filter will be ignored
});

@@ -47,3 +54,3 @@ // Read lines in from a file until you hit the end

while(f.hasNextLine()) {
util.puts(x.getNextLine());
util.puts(f.getNextLine());
}

@@ -63,4 +70,7 @@

});
// If you're feeling somewhat masochistic
wrench.copyDirRecursive(srcDir, newDir, {forceDelete: bool /* See sync version */}, callbackfn);
```
Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)

@@ -49,2 +49,11 @@ var testCase = require('nodeunit').testCase;

});
},
test_readdirRecursiveWithNonExistentDirectory: function(test) {
wrench.readdirRecursive('', function (e, files) {
test.ok(e);
test.equal(e.code, 'ENOENT');
test.equal(files, null);
test.done();
});
}

@@ -51,0 +60,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc