0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Merge pull request #4226 from jaswilli/issue-4225

Follow symlinks when resolving theme paths.
This commit is contained in:
Hannah Wolfe 2014-10-04 19:46:56 +01:00
commit 79c3f51950
3 changed files with 25 additions and 9 deletions

View file

@ -98,11 +98,6 @@ validateSettings = function (defaultSettings, model) {
return Promise.resolve();
};
// A Promise that will resolve to an object with a property for each installed theme.
// This is necessary because certain configuration data is only available while Ghost
// is running and at times the validations are used when it's not (e.g. tests)
availableThemes = requireTree(config.paths.themePath);
validateActiveTheme = function (themeName) {
// If Ghost is running and its availableThemes collection exists
// give it priority.
@ -110,6 +105,13 @@ validateActiveTheme = function (themeName) {
availableThemes = Promise.resolve(config.paths.availableThemes);
}
if (!availableThemes) {
// A Promise that will resolve to an object with a property for each installed theme.
// This is necessary because certain configuration data is only available while Ghost
// is running and at times the validations are used when it's not (e.g. tests)
availableThemes = requireTree(config.paths.themePath);
}
return availableThemes.then(function (themes) {
if (!themes.hasOwnProperty(themeName)) {
return Promise.reject(new errors.ValidationError(themeName + ' cannot be activated because it is not currently installed.', 'activeTheme'));

View file

@ -19,7 +19,7 @@ models = {
self.Base = require('./base');
// Require all files in this directory
return requireTree.readAll(__dirname).then(function (modelFiles) {
return requireTree.readAll(__dirname, {followSymlinks: false}).then(function (modelFiles) {
// For each found file, excluding those we don't want,
// we will require it and cache it here.
_.each(modelFiles, function (path, fileName) {

View file

@ -2,8 +2,9 @@ var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
readdirAsync = Promise.promisify(fs.readdir),
lstatAsync = Promise.promisify(fs.lstat),
readdirAsync = Promise.promisify(fs.readdir),
lstatAsync = Promise.promisify(fs.lstat),
readlinkAsync = Promise.promisify(fs.readlink),
parsePackageJson = function (path, messages) {
// Default the messages if non were passed
@ -56,7 +57,8 @@ var _ = require('lodash'),
};
options = _.extend({
index: true
index: true,
followSymlinks: true
}, options);
if (depth > 1) {
@ -72,6 +74,18 @@ var _ = require('lodash'),
return lstatAsync(fpath).then(function (result) {
if (result.isDirectory()) {
return readDir(fpath, options, depth + 1, messages);
} else if (options.followSymlinks && result.isSymbolicLink()) {
return readlinkAsync(fpath).then(function (linkPath) {
linkPath = path.resolve(dir, linkPath);
return lstatAsync(linkPath).then(function (result) {
if (result.isFile()) {
return linkPath;
}
return readDir(linkPath, options, depth + 1, messages);
});
});
} else if (depth === 1 && file === 'package.json') {
return parsePackageJson(fpath, messages);
} else {