Skip to content

Commit b5e1570

Browse files
Blaimiphated
authored andcommitted
Fix: Ensure symbolic link files are cloned properly (closes #143) (#146)
1 parent ec0ca87 commit b5e1570

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ File.prototype.clone = function(opt) {
128128
contents: contents,
129129
});
130130

131+
if (this.isSymbolic()) {
132+
file.symlink = this.symlink;
133+
}
134+
131135
// Clone our custom properties
132136
Object.keys(this).forEach(function(key) {
133137
if (self.constructor.isCustomProp(key)) {

test/file.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ describe('File', function() {
419419

420420
describe('clone()', function() {
421421

422+
var fakeStat = {
423+
isSymbolicLink: function() {
424+
return true;
425+
},
426+
};
427+
422428
it('copies all attributes over with Buffer contents', function(done) {
423429
var options = {
424430
cwd: '/',
@@ -577,6 +583,24 @@ describe('File', function() {
577583
], done);
578584
});
579585

586+
it('fixes file.symlink if file is a symbolic link', function(done) {
587+
var val = '/test/test.js';
588+
var options = {
589+
cwd: '/',
590+
base: '/test/',
591+
path: '/test/test.coffee',
592+
content: null,
593+
stat: fakeStat,
594+
symlink: val,
595+
};
596+
var file = new File(options);
597+
var file2 = file.clone();
598+
599+
expect(file2).toNotBe(file);
600+
expect(file2.symlink).toEqual(file.symlink);
601+
done();
602+
});
603+
580604
it('copies all attributes over with null contents', function(done) {
581605
var options = {
582606
cwd: '/',

0 commit comments

Comments
 (0)