Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #79 from xzyfer/fix/sync-absolute-symlink
Browse files Browse the repository at this point in the history
Fix inflateSymlinks flag errors for absolute symlinks
  • Loading branch information
Ryan McGrath committed Feb 10, 2014
2 parents 6b80b65 + b0455c9 commit 666e0c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/wrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,19 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
exports.copyDirSyncRecursive(_path.join(sourceDir, files[i]), _path.join(newDirLocation, files[i]), opts);
} else if(currFile.isSymbolicLink()) {
var symlinkFull = fs.readlinkSync(_path.join(sourceDir, files[i]));
symlinkFull = _path.resolve(fs.realpathSync(sourceDir), symlinkFull);

if (typeof opts !== 'undefined' && !opts.inflateSymlinks) {
fs.symlinkSync(symlinkFull, _path.join(newDirLocation, files[i]));
continue;
}

var tmpCurrFile = fs.lstatSync(_path.join(sourceDir, symlinkFull));
var tmpCurrFile = fs.lstatSync(symlinkFull);
if (tmpCurrFile.isDirectory()) {
exports.copyDirSyncRecursive(_path.join(sourceDir, symlinkFull), _path.join(newDirLocation, files[i]), opts);
exports.copyDirSyncRecursive(symlinkFull, _path.join(newDirLocation, files[i]), opts);
} else {
/* At this point, we've hit a file actually worth copying... so copy it on over. */
fCopyFile(_path.join(sourceDir, symlinkFull), _path.join(newDirLocation, files[i]));
fCopyFile(symlinkFull, _path.join(newDirLocation, files[i]));
}
} else {
/* At this point, we've hit a file actually worth copying... so copy it on over. */
Expand Down
36 changes: 36 additions & 0 deletions tests/copydirsync_unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ function checkResultInflate(test, files) {
test.deepEqual(fs.lstatSync(path.join(__dirname, 'testdir/bar.txt')).isSymbolicLink(), false);
}

function checkResultInflateAbsolute(test, files) {
var check = [
'.hidden',
'absolute-bar.txt',
'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',
Expand Down Expand Up @@ -134,6 +149,27 @@ module.exports = testCase({

test.done();
},
test_copyDirSyncRecursiveInflateAbsoluteSymlinks: function(test) {
var dir = path.join(__dirname, 'withsymlinks');
var testdir = path.join(__dirname, 'testdir');

fs.symlinkSync(
path.resolve(__dirname, 'shown/bar.txt'),
path.join(dir, 'absolute-bar.txt')
);

wrench.mkdirSyncRecursive(testdir, 0777);
wrench.copyDirSyncRecursive(dir, testdir, { forceDelete: true, excludeHiddenUnix: false, inflateSymlinks: true });

var files = wrench.readdirSyncRecursive(testdir);

checkResultInflateAbsolute(test, files);

wrench.rmdirSyncRecursive(testdir);
fs.unlinkSync(path.join(dir, 'absolute-bar.txt'));

test.done();
},
test_copyDirSyncRecursiveDontInflate: function(test) {
var dir = path.join(__dirname, 'withsymlinks');
var testdir = path.join(__dirname, 'testdir');
Expand Down

0 comments on commit 666e0c7

Please sign in to comment.