Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode parameter to symlink #469

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -390,4 +390,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);
});
});
});