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:
commit
79c3f51950
3 changed files with 25 additions and 9 deletions
|
@ -98,11 +98,6 @@ validateSettings = function (defaultSettings, model) {
|
||||||
return Promise.resolve();
|
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) {
|
validateActiveTheme = function (themeName) {
|
||||||
// If Ghost is running and its availableThemes collection exists
|
// If Ghost is running and its availableThemes collection exists
|
||||||
// give it priority.
|
// give it priority.
|
||||||
|
@ -110,6 +105,13 @@ validateActiveTheme = function (themeName) {
|
||||||
availableThemes = Promise.resolve(config.paths.availableThemes);
|
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) {
|
return availableThemes.then(function (themes) {
|
||||||
if (!themes.hasOwnProperty(themeName)) {
|
if (!themes.hasOwnProperty(themeName)) {
|
||||||
return Promise.reject(new errors.ValidationError(themeName + ' cannot be activated because it is not currently installed.', 'activeTheme'));
|
return Promise.reject(new errors.ValidationError(themeName + ' cannot be activated because it is not currently installed.', 'activeTheme'));
|
||||||
|
|
|
@ -19,7 +19,7 @@ models = {
|
||||||
self.Base = require('./base');
|
self.Base = require('./base');
|
||||||
|
|
||||||
// Require all files in this directory
|
// 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,
|
// For each found file, excluding those we don't want,
|
||||||
// we will require it and cache it here.
|
// we will require it and cache it here.
|
||||||
_.each(modelFiles, function (path, fileName) {
|
_.each(modelFiles, function (path, fileName) {
|
||||||
|
|
|
@ -2,8 +2,9 @@ var _ = require('lodash'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
readdirAsync = Promise.promisify(fs.readdir),
|
readdirAsync = Promise.promisify(fs.readdir),
|
||||||
lstatAsync = Promise.promisify(fs.lstat),
|
lstatAsync = Promise.promisify(fs.lstat),
|
||||||
|
readlinkAsync = Promise.promisify(fs.readlink),
|
||||||
|
|
||||||
parsePackageJson = function (path, messages) {
|
parsePackageJson = function (path, messages) {
|
||||||
// Default the messages if non were passed
|
// Default the messages if non were passed
|
||||||
|
@ -56,7 +57,8 @@ var _ = require('lodash'),
|
||||||
};
|
};
|
||||||
|
|
||||||
options = _.extend({
|
options = _.extend({
|
||||||
index: true
|
index: true,
|
||||||
|
followSymlinks: true
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
if (depth > 1) {
|
if (depth > 1) {
|
||||||
|
@ -72,6 +74,18 @@ var _ = require('lodash'),
|
||||||
return lstatAsync(fpath).then(function (result) {
|
return lstatAsync(fpath).then(function (result) {
|
||||||
if (result.isDirectory()) {
|
if (result.isDirectory()) {
|
||||||
return readDir(fpath, options, depth + 1, messages);
|
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') {
|
} else if (depth === 1 && file === 'package.json') {
|
||||||
return parsePackageJson(fpath, messages);
|
return parsePackageJson(fpath, messages);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue