Skip to content

Commit

Permalink
Merge pull request #129 from blond/issue-128
Browse files Browse the repository at this point in the history
fix(tar-stream): provide target stats for symlink
  • Loading branch information
blond committed Jan 17, 2018
2 parents 697677b + 2ec763b commit 8ee10ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/streams/abstract-writable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ module.exports = class AbstractWritableStream extends stream.Writable {

const file = Object.assign({ relative, stats: lstats }, chunk);

const addDirectory = () => {
const addDirectory = (dirInfo) => {
// ignore empty dir
if (!this._emptyDirs) {
return callback();
}

return this.addDirectory(file, callback);
return this.addDirectory(dirInfo, callback);
};
const addFile = () => {
const addFile = (fileInfo) => {
// ignore empty file
if (!this._emptyFiles && lstats.size === 0) {
return callback();
}

this.addFile(file, callback);
this.addFile(fileInfo, callback);
};

if (lstats.isSymbolicLink()) {
Expand All @@ -117,10 +117,12 @@ module.exports = class AbstractWritableStream extends stream.Writable {
return callback(error);
}

const targetFile = Object.assign({}, file, { stats });

if (stats.isDirectory()) {
addDirectory();
addDirectory(targetFile);
} else {
addFile();
addFile(targetFile);
}
});
}
Expand All @@ -129,10 +131,10 @@ module.exports = class AbstractWritableStream extends stream.Writable {
}

if (lstats.isDirectory()) {
return addDirectory();
return addDirectory(file);
}

addFile();
addFile(file);
});
}
};
17 changes: 17 additions & 0 deletions test/streams/tar-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ test('should take into broken symlinks', async t => {
t.deepEqual(files, [{ path: 'symlink.txt', contents: null, linkpath: '../no-file' }]);
});

test('should follow symlink', async t => {
mockFs({
'file-1.txt': 'Hi!',
'source-dir': {
'symlink.txt': mockFs.symlink({
path: '../file-1.txt'
})
}
});

await packFiles(['symlink.txt'], { followSymlinks: true });

const files = await parseFiles(resdir);

t.deepEqual(files, [{ path: 'symlink.txt', contents: 'Hi!' }]);
});

test('should include empty file', async t => {
mockFs({
'source-dir': {
Expand Down

0 comments on commit 8ee10ed

Please sign in to comment.