Skip to content

Commit

Permalink
Fix: Ensure symbolic link files are cloned properly (closes #143) (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaimi authored and phated committed Sep 22, 2020
1 parent ec0ca87 commit b5e1570
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -128,6 +128,10 @@ File.prototype.clone = function(opt) {
contents: contents,
});

if (this.isSymbolic()) {
file.symlink = this.symlink;
}

// Clone our custom properties
Object.keys(this).forEach(function(key) {
if (self.constructor.isCustomProp(key)) {
Expand Down
24 changes: 24 additions & 0 deletions test/file.js
Expand Up @@ -419,6 +419,12 @@ describe('File', function() {

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

var fakeStat = {
isSymbolicLink: function() {
return true;
},
};

it('copies all attributes over with Buffer contents', function(done) {
var options = {
cwd: '/',
Expand Down Expand Up @@ -577,6 +583,24 @@ describe('File', function() {
], done);
});

it('fixes file.symlink if file is a symbolic link', function(done) {
var val = '/test/test.js';
var options = {
cwd: '/',
base: '/test/',
path: '/test/test.coffee',
content: null,
stat: fakeStat,
symlink: val,
};
var file = new File(options);
var file2 = file.clone();

expect(file2).toNotBe(file);
expect(file2.symlink).toEqual(file.symlink);
done();
});

it('copies all attributes over with null contents', function(done) {
var options = {
cwd: '/',
Expand Down

0 comments on commit b5e1570

Please sign in to comment.