Skip to content

Commit

Permalink
add mode parameter to symlink (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemhenson authored Nov 19, 2020
1 parent 984fa99 commit 043c7e9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,10 @@ Archiver.prototype.setModule = function(module) {
*
* @param {String} filepath The symlink path (within archive).
* @param {String} target The target path (within archive).
* @param {Number} mode Sets the entry permissions.
* @return {this}
*/
Archiver.prototype.symlink = function(filepath, target) {
Archiver.prototype.symlink = function(filepath, target, mode) {
if (this._state.finalize || this._state.aborted) {
this.emit('error', new ArchiverError('QUEUECLOSED'));
return this;
Expand All @@ -878,6 +879,10 @@ Archiver.prototype.symlink = function(filepath, target) {
data.linkname = target.replace(/\\/g, '/');
data.sourceType = 'buffer';

if (typeof mode === "number") {
data.mode = mode;
}

this._entriesCount++;
this._queue.push({
data: data,
Expand Down
37 changes: 37 additions & 0 deletions test/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,41 @@ describe('archiver', function() {
});

});

describe('#symlink', function() {
var actual;
var archive;
var entries = {};

before(function(done) {
archive = archiver('json');
var testStream = new WriteStream('tmp/symlink.json');

testStream.on('close', function() {
actual = helpers.readJSON('tmp/symlink.json');

actual.forEach(function(entry) {
entries[entry.name] = entry;
});

done();
});

archive.pipe(testStream);

archive
.append("file-a", { name: "file-a" })
.symlink("directory-a/symlink-to-file-a", "../file-a")
.symlink("directory-b/directory-c/symlink-to-directory-a", "../../directory-a", 493)
.finalize();
});

it('should append multiple entries', () => {
assert.isArray(actual);
assert.property(entries, 'file-a');
assert.property(entries, 'directory-a/symlink-to-file-a');
assert.property(entries, 'directory-b/directory-c/symlink-to-directory-a');
assert.propertyVal(entries['directory-b/directory-c/symlink-to-directory-a'], 'mode', 493);
});
});
});

0 comments on commit 043c7e9

Please sign in to comment.