Permalink
Browse files

replication redo under way

  • Loading branch information...
1 parent c9fb8b6 commit 43496faa8ea44f33d33cc7fa47fc3861ab73f918 @pgte committed Jan 21, 2011
@@ -9,9 +9,18 @@ var assert = require('assert')
var DB_PATH = __dirname + '/../../tmp/db';
module.exports.setup = function(next) {
- fs.readdirSync(DB_PATH).forEach(function(dir) {
- fs.unlinkSync(DB_PATH + '/' + dir);
- });
+ (function removeFilesUnder(dir) {
+ fs.readdirSync(dir).forEach(function(path) {
+ var path = dir + '/' + path;
+ var stat = fs.statSync(path);
+ if (stat.isFile()) {
+ fs.unlinkSync(path);
+ } else {
+ removeFilesUnder(path);
+ fs.rmdirSync(path);
+ }
+ });
+ })(DB_PATH);
next();
};
@@ -20,12 +20,20 @@ var USERS = {
var USER_COUNT = 7;
module.exports.setup = function(next) {
- fs.readdirSync(MASTER_DB_PATH).forEach(function(dir) {
- fs.unlinkSync(MASTER_DB_PATH + '/' + dir);
- });
- fs.readdirSync(SLAVE_DB_PATH).forEach(function(dir) {
- fs.unlinkSync(SLAVE_DB_PATH + '/' + dir);
- });
+ function removeFilesUnder(dir) {
+ fs.readdirSync(dir).forEach(function(path) {
+ var path = dir + '/' + path;
+ var stat = fs.statSync(path);
+ if (stat.isFile()) {
+ fs.unlinkSync(path);
+ } else {
+ removeFilesUnder(path);
+ fs.rmdirSync(path);
+ }
+ });
+ };
+ removeFilesUnder(MASTER_DB_PATH);
+ removeFilesUnder(SLAVE_DB_PATH);
next();
};
@@ -8,9 +8,18 @@ var assert = require('assert')
var SLAVE_DB_PATH = __dirname + '/../../tmp/db2';
module.exports.setup = function(next) {
- fs.readdirSync(SLAVE_DB_PATH).forEach(function(dir) {
- fs.unlinkSync(SLAVE_DB_PATH + '/' + dir);
- });
+ (function removeFilesUnder(dir) {
+ fs.readdirSync(dir).forEach(function(path) {
+ var path = dir + '/' + path;
+ var stat = fs.statSync(path);
+ if (stat.isFile()) {
+ fs.unlinkSync(path);
+ } else {
+ removeFilesUnder(path);
+ fs.rmdirSync(path);
+ }
+ });
+ })(SLAVE_DB_PATH);
next();
};

0 comments on commit 43496fa

Please sign in to comment.