diff --git a/core/frontend/services/themes/Storage.js b/core/frontend/services/themes/Storage.js index 31b9522035..8429cc727d 100644 --- a/core/frontend/services/themes/Storage.js +++ b/core/frontend/services/themes/Storage.js @@ -48,6 +48,7 @@ module.exports = { } let checkedTheme; + let renamedExisting = false; return validate.checkSafe(zip, true) .then((_checkedTheme) => { @@ -58,6 +59,7 @@ module.exports = { .then((themeExists) => { // CASE: move the existing theme to a backup folder if (themeExists) { + renamedExisting = true; return getStorage().rename(shortName, backupName); } }) @@ -86,6 +88,20 @@ module.exports = { theme: toJSON(shortName, checkedTheme) }; }) + .catch((error) => { + // restore backup if we renamed an existing theme but saving failed + if (renamedExisting) { + return getStorage().exists(shortName).then((themeExists) => { + if (!themeExists) { + return getStorage().rename(backupName, shortName).then(() => { + throw error; + }); + } + }); + } + + throw error; + }) .finally(() => { // @TODO: we should probably do this as part of saving the theme // CASE: remove extracted dir from gscan happens in background diff --git a/package.json b/package.json index d11da9ff9f..d6834f9fbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghost", - "version": "3.41.7", + "version": "3.41.8", "description": "The professional publishing platform", "author": "Ghost Foundation", "homepage": "https://ghost.org", @@ -56,7 +56,7 @@ "@tryghost/kg-markdown-html-renderer": "3.0.0", "@tryghost/kg-mobiledoc-html-renderer": "3.0.1", "@tryghost/magic-link": "0.6.4", - "@tryghost/members-api": "0.37.10", + "@tryghost/members-api": "0.37.11", "@tryghost/members-csv": "0.4.2", "@tryghost/members-ssr": "0.8.8", "@tryghost/mw-session-from-token": "0.1.14", diff --git a/yarn.lock b/yarn.lock index d1388894d9..f1f4dc706f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -553,10 +553,10 @@ jsonwebtoken "^8.5.1" lodash "^4.17.15" -"@tryghost/members-api@0.37.10": - version "0.37.10" - resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.37.10.tgz#73fedfdba1c060109a6df84a5e96a4b4a717e5d4" - integrity sha512-Q4rdNmaouNk3YBv02yUelzL+ETPiGkWGfeuBcw6bcMTOtp4GbsT1MUWxRY8pK50EZJjL1+4+Fj8QlmiCtpfTdQ== +"@tryghost/members-api@0.37.11": + version "0.37.11" + resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.37.11.tgz#a66aa63c04236f2a5fce207567746bf91fb0d59c" + integrity sha512-LMaE1XPDru7kysrFwZ48/gtL2OMVlPUK4DEjLL1ys7seQTKm6ljhalc40rl7zBkvg1nh+br0qcikMSTpng2vzA== dependencies: "@tryghost/magic-link" "^0.6.7" bluebird "^3.5.4"