0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

🐛 🔗 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
This commit is contained in:
Austin Burdine 2017-07-31 03:48:00 -04:00 committed by Katharina Irrgang
parent 923f982fce
commit 65d219c29a
2 changed files with 55 additions and 0 deletions

View file

@ -5,6 +5,12 @@ module.exports = function zipFolder(folderToZip, destination, callback) {
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());
});

View file

@ -0,0 +1,49 @@
var should = require('should'), // jshint ignore:line
path = require('path'),
fs = require('fs-extra'),
extract = require('extract-zip-fork'),
utils = require('../../../server/utils');
describe('Utils: zip-folder', function () {
const symlinkPath = path.join(__dirname, '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink'),
folderToSymlink = path.join(__dirname, '..', '..', 'utils', 'fixtures', 'themes', 'casper'),
zipDestination = path.join(__dirname, '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink.zip'),
unzipDestination = path.join(__dirname, '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink-unzipped');
before(function () {
fs.removeSync(symlinkPath);
fs.removeSync(zipDestination);
fs.removeSync(unzipDestination);
});
after(function () {
fs.removeSync(symlinkPath);
fs.removeSync(zipDestination);
fs.removeSync(unzipDestination);
});
it('ensure symlinks work', function (done) {
fs.symlink(folderToSymlink, symlinkPath);
utils.zipFolder(symlinkPath, zipDestination, function (err) {
if (err) {
return done(err);
}
extract(zipDestination, {dir: unzipDestination}, function (err) {
if (err) {
return done(err);
}
fs.readdir(unzipDestination, function (err, files) {
if (err) {
return done(err);
}
files.length.should.eql(10);
done();
});
});
});
});
});