Skip to content
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
19 changes: 11 additions & 8 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Archiver.prototype._append = function(filepath, data) {

if (data.stats && data.stats instanceof fs.Stats) {
task = this._updateQueueTaskWithStats(task, data.stats);
this._queue.push(task);
if (task) this._queue.push(task);
} else {
this._statQueue.push(task);
}
Expand Down Expand Up @@ -398,14 +398,10 @@ Archiver.prototype._onStatQueueTask = function(task, callback) {

task = this._updateQueueTaskWithStats(task, stats);

if (task.source !== null) {
if (task) {
this._queue.push(task);
setImmediate(callback);
} else {
this.emit('error', new Error('unsupported entry: ' + task.filepath));
setImmediate(callback);
return;
}
setImmediate(callback);
}.bind(this));
};

Expand Down Expand Up @@ -456,8 +452,14 @@ Archiver.prototype._updateQueueTaskWithStats = function(task, stats) {
task.data.sourcePath = util.trailingSlashIt(task.filepath);
task.data.sourceType = 'buffer';
task.source = new Buffer(0);
} else if (stats.isSymbolicLink() && this._moduleSupports('symlink')) {
task.data.type = 'symlink';
task.data.linkname = fs.readlinkSync(task.filepath);
task.data.sourceType = 'buffer';
task.source = new Buffer(0);
} else {
return task;
this.emit('error', new Error('unsupported entry: ' + task.filepath));
return null;
}

task.data = this._normalizeEntryData(task.data, stats);
Expand Down Expand Up @@ -695,6 +697,7 @@ Archiver.prototype.directory = function(dirpath, destpath, data) {
walker.on('error', onWalkError.bind(this));
walker.on('directory', onWalkPath.bind(this));
walker.on('file', onWalkPath.bind(this));
walker.on('link', onWalkPath.bind(this));
walker.on('end', onWalkEnd.bind(this));

return this;
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var Json = function(options) {
Transform.call(this, options);

this.supports = {
directory: true
directory: true,
symlink: true
};

this.files = [];
Expand Down Expand Up @@ -106,4 +107,4 @@ module.exports = Json;
/**
* @typedef {Object} JsonOptions
* @global
*/
*/
5 changes: 3 additions & 2 deletions lib/plugins/tar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var Tar = function(options) {
}

this.supports = {
directory: true
directory: true,
symlink: true
};

this.engine = engine.pack(options);
Expand Down Expand Up @@ -163,4 +164,4 @@ module.exports = Tar;
* TarStream Module
* @external TarStream
* @see {@link https://github.com/mafintosh/tar-stream}
*/
*/
5 changes: 3 additions & 2 deletions lib/plugins/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var Zip = function(options) {
});

this.supports = {
directory: true
directory: true,
symlink: false
};

this.engine = new engine(options);
Expand Down Expand Up @@ -112,4 +113,4 @@ module.exports = Zip;
* ZipStream Module
* @external ZipStream
* @see {@link https://archiverjs.com/zip-stream/ZipStream.html}
*/
*/
4 changes: 3 additions & 1 deletion test/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ describe('archiver', function() {
assert.property(entries, 'test/fixtures/directory/level0.txt');
assert.property(entries, 'test/fixtures/directory/subdir/');
assert.property(entries, 'test/fixtures/directory/subdir/level1.txt');
assert.property(entries, 'test/fixtures/directory/subdir/level0link.txt');
assert.property(entries, 'test/fixtures/directory/subdir/subsub/');
assert.property(entries, 'test/fixtures/directory/subdir/subsub/level2.txt');
assert.propertyVal(entries['test/fixtures/directory/level0.txt'], 'date', '2013-01-03T14:26:38.000Z');
Expand All @@ -187,6 +188,7 @@ describe('archiver', function() {
assert.property(entries, 'directory/level0.txt');
assert.property(entries, 'directory/subdir/');
assert.property(entries, 'directory/subdir/level1.txt');
assert.property(entries, 'directory/subdir/level0link.txt');
assert.property(entries, 'directory/subdir/subsub/');
assert.property(entries, 'directory/subdir/subsub/level2.txt');
});
Expand Down Expand Up @@ -360,4 +362,4 @@ describe('archiver', function() {
});

});
});
});
1 change: 1 addition & 0 deletions test/fixtures/directory/subdir/level0link.txt
25 changes: 16 additions & 9 deletions test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ describe('plugins', function() {
archive
.append(testBuffer, { name: 'buffer.txt', date: testDate })
.append(fs.createReadStream('test/fixtures/test.txt'), { name: 'stream.txt', date: testDate })
.append(null, { name: 'directory/', date: testDate })
.append(null, { name: 'folder/', date: testDate })
.directory('test/fixtures/directory', 'directory')
.finalize();
});

it('should append multiple entries', function() {
assert.isArray(actual);
assert.lengthOf(actual, 3);
assert.lengthOf(actual, 9);
});

it('should append buffer', function() {
Expand All @@ -74,12 +75,18 @@ describe('plugins', function() {
assert.propertyVal(entries['stream.txt'].props, 'size', 19);
});

it('should append directory', function() {
assert.property(entries, 'directory/');
assert.propertyVal(entries['directory/'].props, 'path', 'directory/');
assert.propertyVal(entries['directory/'].props, 'type', '5');
assert.propertyVal(entries['directory/'].props, 'mode', 493);
assert.propertyVal(entries['directory/'].props, 'size', 0);
it('should append folder', function() {
assert.property(entries, 'folder/');
assert.propertyVal(entries['folder/'].props, 'path', 'folder/');
assert.propertyVal(entries['folder/'].props, 'type', '5');
assert.propertyVal(entries['folder/'].props, 'mode', 493);
assert.propertyVal(entries['folder/'].props, 'size', 0);
});

it('should append via directory', function() {
assert.property(entries, 'directory/subdir/level1.txt');
assert.property(entries, 'directory/subdir/level0link.txt');
assert.propertyVal(entries['directory/subdir/level0link.txt'].props, 'linkpath', '../level0.txt');
});
});

Expand Down Expand Up @@ -166,4 +173,4 @@ describe('plugins', function() {
assert.equal('archive comment', zipComment);
});
});
});
});