Ghost/core/server/utils/zip-folder.js
Austin Burdine 65d219c29a 🐛 🔗 resolve symlinks before building zip (#8780)
closes #8778

- if folderToZip is a symlink, find the target using fs.realPathSync so we zip the right thing
- add a test
2017-07-31 11:48:00 +04:00

26 lines
740 B
JavaScript

var fs = require('fs');
module.exports = function zipFolder(folderToZip, destination, callback) {
var archiver = require('archiver'),
output = fs.createWriteStream(destination),
archive = archiver.create('zip', {});
// If folder to zip is a symlink, we want to get the target
// of the link and zip that instead of zipping the symlink
if (fs.lstatSync(folderToZip).isSymbolicLink()) {
folderToZip = fs.realpathSync(folderToZip);
}
output.on('close', function () {
callback(null, archive.pointer());
});
archive.on('error', function (err) {
callback(err, null);
});
archive.directory(folderToZip, '/');
archive.pipe(output);
archive.finalize();
};