mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Fixed fs error during theme install deleting active theme (#12688)
closes https://github.com/TryGhost/Ghost/issues/12506 - adds an error handler that will rename the backup folder to the original name if the newly uploaded theme wasn't saved successfully
This commit is contained in:
parent
08e1268aed
commit
519faf8749
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user