Skip to content

Commit

Permalink
Added temp file cleanup for invalid themes
Browse files Browse the repository at this point in the history
refs #10174

- When theme check fails with validation error there was no cleanup of files left from zip extraction
  • Loading branch information
naz committed May 2, 2019
1 parent a77190a commit f21e713
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/server/services/themes/validate.js
@@ -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');

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f21e713

Please sign in to comment.