Comparing version 1.4.1 to 1.4.2
@@ -154,3 +154,3 @@ /* wrench.js | ||
/* 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); | ||
@@ -196,2 +196,10 @@ }; | ||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]); | ||
var fCopyFile = function(srcFile, destFile) { | ||
if (opts.preserveFiles && fs.existsSync(destFile)) return; | ||
var contents = fs.readFileSync(srcFile); | ||
fs.writeFileSync(destFile, contents); | ||
}; | ||
if(currFile.isDirectory()) { | ||
@@ -202,7 +210,18 @@ /* recursion this thing right on back. */ | ||
var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]); | ||
fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]); | ||
if (!opts.inflateSymlinks) { | ||
fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]); | ||
continue; | ||
} | ||
var tmpCurrFile = fs.lstatSync(sourceDir + "/" + symlinkFull); | ||
if (tmpCurrFile.isDirectory()) { | ||
exports.copyDirSyncRecursive(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i], opts); | ||
} else { | ||
/* At this point, we've hit a file actually worth copying... so copy it on over. */ | ||
fCopyFile(sourceDir + "/" + symlinkFull, newDirLocation + "/" + files[i]); | ||
} | ||
} 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); | ||
fCopyFile(sourceDir + "/" + files[i], newDirLocation + "/" + files[i]); | ||
} | ||
@@ -209,0 +228,0 @@ } |
{ | ||
"name": "wrench", | ||
"description": "Recursive filesystem (and other) operations that Node *should* have.", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"author": "Ryan McGrath <ryan@venodesigns.net>", | ||
@@ -6,0 +6,0 @@ |
@@ -35,2 +35,46 @@ var testCase = require('nodeunit').testCase; | ||
function checkResultInflate(test, files) { | ||
var check = [ | ||
'.hidden', | ||
'bar.txt', | ||
'test', | ||
path.join('.hidden', 'dolor.md') | ||
]; | ||
test.deepEqual(files, check); | ||
test.deepEqual(fs.lstatSync(path.join(__dirname, 'testdir/.hidden')).isSymbolicLink(), false); | ||
test.deepEqual(fs.lstatSync(path.join(__dirname, 'testdir/bar.txt')).isSymbolicLink(), false); | ||
} | ||
function checkResultDontInflate(test, files) { | ||
var check = [ | ||
'.hidden', | ||
'bar.txt', | ||
'test', | ||
path.join('.hidden', 'dolor.md') | ||
]; | ||
test.deepEqual(files, check); | ||
test.deepEqual(fs.lstatSync(path.join(__dirname, 'testdir/.hidden')).isSymbolicLink(), true); | ||
test.deepEqual(fs.lstatSync(path.join(__dirname, 'testdir/bar.txt')).isSymbolicLink(), true); | ||
} | ||
function checkResultPreserveFiles(test, files) { | ||
checkResultHidden(test, files); | ||
var contents = fs.readFileSync(path.join(__dirname, path.join('testdir2', '.hidden.txt')), "utf8"); | ||
test.deepEqual(contents, 'hidden file'); | ||
contents = fs.readFileSync(path.join(__dirname, path.join('testdir2', 'bar.txt')), "utf8"); | ||
test.deepEqual(contents, 'shown file'); | ||
} | ||
function checkResultOverwriteFiles(test, files) { | ||
checkResultHidden(test, files); | ||
var contents = fs.readFileSync(path.join(__dirname, path.join('testdir2', '.hidden.txt')), "utf8"); | ||
test.deepEqual(contents, 'just some text for .hidden.txt'); | ||
contents = fs.readFileSync(path.join(__dirname, path.join('testdir2', 'bar.txt')), "utf8"); | ||
test.deepEqual(contents, 'just some text for bar.txt'); | ||
} | ||
module.exports = testCase({ | ||
@@ -70,5 +114,90 @@ test_copyDirSyncRecursiveHidden: function(test) { | ||
test.done(); | ||
}, | ||
test_copyDirSyncRecursiveInflate: function(test) { | ||
var dir = path.join(__dirname, 'withsymlinks'); | ||
var testdir = path.join(__dirname, 'testdir'); | ||
test.ok(path.existsSync(dir), 'Folders should exist'); | ||
wrench.mkdirSyncRecursive(testdir, 0777); | ||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: true }); | ||
var files = wrench.readdirSyncRecursive(testdir); | ||
checkResultInflate(test, files); | ||
wrench.rmdirSyncRecursive(testdir); | ||
test.done(); | ||
}, | ||
test_copyDirSyncRecursiveDontInflate: function(test) { | ||
var dir = path.join(__dirname, 'withsymlinks'); | ||
var testdir = path.join(__dirname, 'testdir'); | ||
test.ok(path.existsSync(dir), 'Folders should exist'); | ||
wrench.mkdirSyncRecursive(testdir, 0777); | ||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false, inflateSymlinks: false }); | ||
var files = wrench.readdirSyncRecursive(testdir); | ||
checkResultDontInflate(test, files); | ||
wrench.rmdirSyncRecursive(testdir); | ||
test.done(); | ||
}, | ||
test_copyDirSyncRecursivePreserveFiles: function(test) { | ||
var dir = path.join(__dirname, 'shown'), | ||
testdir1 = path.join(__dirname, 'testdir1'), | ||
testdir2 = path.join(__dirname, 'testdir2'); | ||
test.ok(path.existsSync(dir), 'Folders should exist'); | ||
wrench.mkdirSyncRecursive(testdir1, 0777); | ||
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false }); | ||
wrench.copyDirSyncRecursive(dir, testdir2, { excludeHiddenUnix: false }); | ||
fs.writeFileSync(path.join(testdir1, ".hidden.txt"), 'just some text for .hidden.txt'); | ||
fs.writeFileSync(path.join(testdir1, "bar.txt"), 'just some text for bar.txt'); | ||
wrench.copyDirSyncRecursive(testdir1, testdir2, { preserve: true, excludeHiddenUnix: false, preserveFiles: true }); | ||
var files = wrench.readdirSyncRecursive(testdir2); | ||
checkResultPreserveFiles(test, files); | ||
wrench.rmdirSyncRecursive(testdir1); | ||
wrench.rmdirSyncRecursive(testdir2); | ||
test.done(); | ||
}, | ||
test_copyDirSyncRecursiveOverwriteFiles: function(test) { | ||
var dir = path.join(__dirname, 'shown'), | ||
testdir1 = path.join(__dirname, 'testdir1'), | ||
testdir2 = path.join(__dirname, 'testdir2'); | ||
test.ok(path.existsSync(dir), 'Folders should exist'); | ||
wrench.mkdirSyncRecursive(testdir1, 0777); | ||
wrench.copyDirSyncRecursive(dir, testdir1, { excludeHiddenUnix: false }); | ||
wrench.copyDirSyncRecursive(dir, testdir2, { excludeHiddenUnix: false }); | ||
fs.writeFileSync(path.join(testdir1, ".hidden.txt"), 'just some text for .hidden.txt'); | ||
fs.writeFileSync(path.join(testdir1, "bar.txt"), 'just some text for bar.txt'); | ||
wrench.copyDirSyncRecursive(testdir1, testdir2, { preserve: true, excludeHiddenUnix: false, preserveFiles: false }); | ||
var files = wrench.readdirSyncRecursive(testdir2); | ||
checkResultOverwriteFiles(test, files); | ||
wrench.rmdirSyncRecursive(testdir1); | ||
wrench.rmdirSyncRecursive(testdir2); | ||
test.done(); | ||
} | ||
}); | ||
// vim: et ts=4 sw=4 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27558
21
566