0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added temp file cleanup for invalid themes

refs #10174

- When theme check fails with validation error there was no cleanup of files left from zip extraction
This commit is contained in:
Nazar Gargol 2019-05-02 17:59:29 +02:00
parent a77190a312
commit f21e713a83

View file

@ -1,5 +1,6 @@
const _ = require('lodash');
const Promise = require('bluebird');
const fs = require('fs-extra');
const config = require('../../config');
const common = require('../../lib/common');
@ -39,6 +40,16 @@ const checkSafe = function checkSafe(theme, isZip) {
return checkedTheme;
}
// NOTE: When theme cannot be activated and gscan explicitly keeps extracted files (after
// being called with `keepExtractedDir: true`), this is the closes place for a cleanup.
// TODO: The `keepExtractedDir` flag is the cause of confusion for when and where the cleanup
// should be done. It's probably best if gscan is called directly with path to the extracted
// directory, this would allow keeping gscan to do just one thing - validate the theme, and
// file manipulations could be left to another module/library
if (isZip) {
fs.remove(checkedTheme.path);
}
return Promise.reject(new common.errors.ThemeValidationError({
message: common.i18n.t('errors.api.themes.invalidTheme'),
errorDetails: Object.assign(