Updating test for rmdirSyncRecursive to check for files with alternative permissions being removed properly.

This commit is contained in:
seanmwalker 2014-01-17 01:28:55 -06:00
parent 793c61eec0
commit df61c7017f
2 changed files with 59 additions and 2 deletions

View file

@ -135,6 +135,8 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
try { try {
files = fs.readdirSync(path); files = fs.readdirSync(path);
} catch (err) { } catch (err) {
console.log('Error "' + err.message + '"\n');
if(failSilent) return; if(failSilent) return;
throw new Error(err.message); throw new Error(err.message);
} }
@ -150,6 +152,7 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
} else if(currFile.isSymbolicLink()) { } else if(currFile.isSymbolicLink()) {
// Unlink symlinks // Unlink symlinks
if (isWindows) { if (isWindows) {
console.log('Remove file "' + file + '"\n');
fs.chmodSync(file, 666) // Windows needs this unless joyent/node#3006 is resolved.. fs.chmodSync(file, 666) // Windows needs this unless joyent/node#3006 is resolved..
} }
@ -157,6 +160,7 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
} else { } else {
// Assume it's a file - perhaps a try/catch belongs here? // Assume it's a file - perhaps a try/catch belongs here?
if (isWindows) { if (isWindows) {
console.log('Remove file "' + file + '"\n');
fs.chmodSync(file, 666) // Windows needs this unless joyent/node#3006 is resolved.. fs.chmodSync(file, 666) // Windows needs this unless joyent/node#3006 is resolved..
} }
@ -164,6 +168,7 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
} }
} }
console.log('Remove dir "' + path + '"\n');
/* Now that we know everything in the sub-tree has been deleted, we can delete the main /* Now that we know everything in the sub-tree has been deleted, we can delete the main
directory. Huzzah for the shopkeep. */ directory. Huzzah for the shopkeep. */
return fs.rmdirSync(path); return fs.rmdirSync(path);

View file

@ -5,18 +5,70 @@ var path = require('path');
module.exports = testCase({ module.exports = testCase({
test_rmdirSyncRecursive: function(test) { test_rmdirSyncRecursive: function(test) {
var dir = __dirname + '/_tmp/foo/bar'; var dir = __dirname + '/_tmp2/foo/bar';
wrench.mkdirSyncRecursive(dir, 0777); wrench.mkdirSyncRecursive(dir, '777');
var f1Path = path.join(dir, 'test1.txt');
var f2Path = path.join(path.dirname(dir), 'test2.txt');
var f3Path = path.join(path.dirname(path.dirname(dir)), 'test3.txt');
fs.writeFileSync(f1Path, 'foo bar baz');
fs.writeFileSync(f2Path, 'foo bar baz');
fs.writeFileSync(f3Path, 'foo bar baz');
fs.chmodSync(f1Path, '777');
fs.chmodSync(f2Path, '777');
fs.chmodSync(f3Path, '777');
test.equals(fs.existsSync(dir), true, 'Dir should exist - mkdirSyncRecursive not working?'); test.equals(fs.existsSync(dir), true, 'Dir should exist - mkdirSyncRecursive not working?');
test.equals(fs.existsSync(f1Path), true, 'File should exist');
test.equals(fs.existsSync(f2Path), true, 'File should exist');
test.equals(fs.existsSync(f3Path), true, 'File should exist');
wrench.rmdirSyncRecursive(dir); wrench.rmdirSyncRecursive(dir);
test.equals(fs.existsSync(dir), false, 'Dir should not exist now...'); test.equals(fs.existsSync(dir), false, 'Dir should not exist now...');
test.equals(fs.existsSync(f1Path), false, 'File should not exist');
test.equals(fs.existsSync(f2Path), true, 'File should exist');
test.equals(fs.existsSync(f3Path), true, 'File should exist');
wrench.rmdirSyncRecursive(path.dirname(path.dirname(dir)));
test.done(); test.done();
}, },
test_rmdirSyncRecursiveFromRoot: function(test) {
var dir = __dirname + '/_tmp3/foo/bar';
wrench.mkdirSyncRecursive(dir, '777');
var f1Path = path.join(dir, 'test1.txt');
var f2Path = path.join(path.dirname(dir), 'test2.txt');
var f3Path = path.join(path.dirname(path.dirname(dir)), 'test3.txt');
fs.writeFileSync(f1Path, 'foo bar baz');
fs.writeFileSync(f2Path, 'foo bar baz');
fs.writeFileSync(f3Path, 'foo bar baz');
fs.chmodSync(f1Path, '777');
fs.chmodSync(f2Path, '777');
fs.chmodSync(f3Path, '777');
test.equals(fs.existsSync(dir), true, 'Dir should exist - mkdirSyncRecursive not working?');
test.equals(fs.existsSync(f1Path), true, 'File should exist');
test.equals(fs.existsSync(f2Path), true, 'File should exist');
test.equals(fs.existsSync(f3Path), true, 'File should exist');
wrench.rmdirSyncRecursive(path.dirname(path.dirname(dir)));
test.equals(fs.existsSync(dir), false, 'Dir should not exist now...');
test.equals(fs.existsSync(f1Path), false, 'File should not exist');
test.equals(fs.existsSync(f2Path), false, 'File should not exist');
test.equals(fs.existsSync(f3Path), false, 'File should not exist');
test.done();
}
}); });
// vim: et ts=4 sw=4 // vim: et ts=4 sw=4