Ghost/core/server/config/utils.js
Katharina Irrgang fd0a08ae8c 🎨 make sqlite filename absolute (#7585)
no issue

- add tests for makePathsAbsolute
- add support for windows paths

When Ghost-CLI inits the database of the current GhostVersion (in /current), then it uses knex-migrator to do that.
Knex migrator is reading the .knex-migrator file of the current Ghost version. This returns a relative path to the database location.
The problem: knex-migrator will init the database in the root folder of Ghost-CLI /content/data instead of /current/content . And when you start Ghost (ghost start), it always complains that
that database is not initialised, because it expects the database in /current/content...

* 🎨  move config_spec to config/index_spec
- add one more test case
2016-10-18 09:04:44 +01:00

75 lines
2.4 KiB
JavaScript

var path = require('path'),
_ = require('lodash'),
errors = require('../errors');
exports.isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
if (!this.get('privacy')) {
return false;
}
if (this.get('privacy').useTinfoil === true) {
return true;
}
return this.get('privacy')[privacyFlag] === false;
};
/**
* transform all relative paths to absolute paths
* @TODO: imagesRelPath is a dirty little attribute (especially when looking at the usages)
* @TODO: re-write this function a little bit so we don't have to add the parent path - that is hard to understand
*
* Path must be string.
* Path must match minimum one / or \
* Path can be a "." to re-present current folder
*/
exports.makePathsAbsolute = function makePathsAbsolute(obj, parent) {
var self = this;
if (!obj) {
throw new errors.IncorrectUsageError({
message: 'makePathsAbsolute: Object is missing.'
});
}
if (!parent) {
throw new errors.IncorrectUsageError({
message: 'makePathsAbsolute: Parent is missing.'
});
}
_.each(obj, function (configValue, pathsKey) {
if (_.isObject(configValue)) {
makePathsAbsolute.bind(self)(configValue, parent + ':' + pathsKey);
} else {
if (_.isString(configValue) &&
(configValue.match(/\/+|\\+/) || configValue === '.') &&
(configValue[0] !== '/' && configValue[0] !== '\\') &&
pathsKey !== 'imagesRelPath'
) {
self.set(parent + ':' + pathsKey, path.join(__dirname + '/../../../', configValue));
}
}
});
};
/**
* we can later support setting folder names via custom config values
*/
exports.getContentPath = function getContentPath(type) {
switch (type) {
case 'storage':
return path.join(this.get('paths:contentPath'), 'storage/');
case 'images':
return path.join(this.get('paths:contentPath'), 'images/');
case 'apps':
return path.join(this.get('paths:contentPath'), 'apps/');
case 'themes':
return path.join(this.get('paths:contentPath'), 'themes/');
case 'scheduling':
return path.join(this.get('paths:contentPath'), 'scheduling/');
default:
throw new Error('getContentPath was called with: ' + type);
}
};