Skip to content
Browse files

normalize tabs

  • Loading branch information...
1 parent 5a6372f commit 29cb04590b2b77d14eb9f3a6c5ebf4d740f06804 @millermedeiros millermedeiros committed Jan 14, 2012
Showing with 64 additions and 64 deletions.
  1. +64 −64 lib/wrench.js
View
128 lib/wrench.js
@@ -20,14 +20,14 @@ var fs = require("fs");
* Asynchronous version. :\
*/
exports.rmdirSyncRecursive = function(path, failSilent) {
- var files;
-
- try {
- files = fs.readdirSync(path);
+ var files;
+
+ try {
+ files = fs.readdirSync(path);
} catch (err) {
- if(failSilent) return;
- throw new Error(err.message);
- }
+ if(failSilent) return;
+ throw new Error(err.message);
+ }
/* Loop through and delete everything in the sub-tree after checking it */
for(var i = 0; i < files.length; i++) {
@@ -57,21 +57,21 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
* Note: Directories should be passed to this function without a trailing slash.
*/
exports.copyDirSyncRecursive = function(sourceDir, newDirLocation) {
- /* Copying over something is... tricky. The user should know what they're doing at this point, so...
+ /* Copying over something is... tricky. The user should know what they're doing at this point, so...
* blow any existing directory away!
*/
try {
if(fs.statSync(newDirLocation).isDirectory()) exports.rmdirSyncRecursive(newDirLocation);
} catch(e) { }
/* Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */
- var checkDir = fs.statSync(sourceDir);
+ var checkDir = fs.statSync(sourceDir);
fs.mkdirSync(newDirLocation, checkDir.mode);
var files = fs.readdirSync(sourceDir);
- for(var i = 0; i < files.length; i++) {
- var currFile = fs.statSync(sourceDir + "/" + files[i]);
+ for(var i = 0; i < files.length; i++) {
+ var currFile = fs.statSync(sourceDir + "/" + files[i]);
if(currFile.isDirectory()) {
/* Create a new directory in our copied version... */
@@ -85,8 +85,8 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation) {
} else {
/* At this point, we've hit a file actually worth copying... so copy it on over. */
var contents = fs.readFileSync(sourceDir + "/" + files[i]);
- fs.writeFileSync(newDirLocation + "/" + files[i], contents);
- }
+ fs.writeFileSync(newDirLocation + "/" + files[i], contents);
+ }
}
};
@@ -100,16 +100,16 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation) {
exports.chmodSyncRecursive = function(sourceDir, filemode) {
var files = fs.readdirSync(sourceDir);
- for(var i = 0; i < files.length; i++) {
- var currFile = fs.statSync(sourceDir + "/" + files[i]);
+ for(var i = 0; i < files.length; i++) {
+ var currFile = fs.statSync(sourceDir + "/" + files[i]);
if(currFile.isDirectory()) {
/* ...and recursion this thing right on back. */
exports.chmodSyncRecursive(sourceDir + "/" + files[i], filemode);
} else {
/* At this point, we've hit a file actually worth copying... so copy it on over. */
fs.chmod(sourceDir + "/" + files[i], filemode);
- }
+ }
}
/* Finally, chmod the parent directory */
@@ -127,16 +127,16 @@ exports.chmodSyncRecursive = function(sourceDir, filemode) {
exports.chownSyncRecursive = function(sourceDir, uid, gid) {
var files = fs.readdirSync(sourceDir);
- for(var i = 0; i < files.length; i++) {
- var currFile = fs.statSync(sourceDir + "/" + files[i]);
+ for(var i = 0; i < files.length; i++) {
+ var currFile = fs.statSync(sourceDir + "/" + files[i]);
if(currFile.isDirectory()) {
/* ...and recursion this thing right on back. */
exports.chownSyncRecursive(sourceDir + "/" + files[i], uid, gid);
} else {
/* At this point, we've hit a file actually worth chowning... so own it. */
fs.chownSync(sourceDir + "/" + files[i], uid, gid);
- }
+ }
}
/* Finally, chown the parent directory */
@@ -220,64 +220,64 @@ exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, clbk) {
};
var mkdirSyncRecursive = function(path, mode) {
- var self = this;
-
- try {
- fs.mkdirSync(path, mode);
- } catch(err) {
- if(err.code == "ENOENT") {
- var slashIdx = path.lastIndexOf("/");
- if(slashIdx > 0) {
- var parentPath = path.substring(0, slashIdx);
- mkdirSyncRecursive(parentPath, mode);
- mkdirSyncRecursive(path, mode);
- } else {
- throw err;
- }
- } else if(err.code == "EEXIST") {
- return;
- } else {
- throw err;
- }
- }
+ var self = this;
+
+ try {
+ fs.mkdirSync(path, mode);
+ } catch(err) {
+ if(err.code == "ENOENT") {
+ var slashIdx = path.lastIndexOf("/");
+ if(slashIdx > 0) {
+ var parentPath = path.substring(0, slashIdx);
+ mkdirSyncRecursive(parentPath, mode);
+ mkdirSyncRecursive(path, mode);
+ } else {
+ throw err;
+ }
+ } else if(err.code == "EEXIST") {
+ return;
+ } else {
+ throw err;
+ }
+ }
};
exports.mkdirSyncRecursive = mkdirSyncRecursive;
exports.LineReader = function(filename, bufferSize) {
- this.bufferSize = bufferSize || 8192;
- this.buffer = "";
- this.fd = fs.openSync(filename, "r");
- this.currentPosition = 0;
+ this.bufferSize = bufferSize || 8192;
+ this.buffer = "";
+ this.fd = fs.openSync(filename, "r");
+ this.currentPosition = 0;
}
exports.LineReader.prototype = {
- getBufferAndSetCurrentPosition: function(position) {
- var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");
+ getBufferAndSetCurrentPosition: function(position) {
+ var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");
- this.buffer += res[0];
- if(res[1] === 0) return -1;
+ this.buffer += res[0];
+ if(res[1] === 0) return -1;
- this.currentPosition = position + res[1];
- return this.currentPosition;
- },
+ this.currentPosition = position + res[1];
+ return this.currentPosition;
+ },
- hasNextLine: function() {
- while(this.buffer.indexOf('\n') === -1) {
- this.getBufferAndSetCurrentPosition(this.currentPosition);
- if(this.currentPosition === -1) return false;
- }
+ hasNextLine: function() {
+ while(this.buffer.indexOf('\n') === -1) {
+ this.getBufferAndSetCurrentPosition(this.currentPosition);
+ if(this.currentPosition === -1) return false;
+ }
- if(this.buffer.indexOf("\n") > -1) return true;
- return false;
- },
+ if(this.buffer.indexOf("\n") > -1) return true;
+ return false;
+ },
- getNextLine: function() {
- var lineEnd = this.buffer.indexOf("\n"),
- result = this.buffer.substring(0, lineEnd);
+ getNextLine: function() {
+ var lineEnd = this.buffer.indexOf("\n"),
+ result = this.buffer.substring(0, lineEnd);
- this.buffer = this.buffer.substring(result.length + 1, this.buffer.length);
- return result;
- }
+ this.buffer = this.buffer.substring(result.length + 1, this.buffer.length);
+ return result;
+ }
};
// vim: et ts=4 sw=4

0 comments on commit 29cb045

Please sign in to comment.
Something went wrong with that request. Please try again.