Skip to content

Commit

Permalink
Fix backups not restoring for databaseless
Browse files Browse the repository at this point in the history
  • Loading branch information
synzen committed Feb 1, 2020
1 parent 2efba98 commit 6bc82d4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions util/dbOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ exports.guildRss = {
restore: async guildId => {
// Memory version
let guildRss
const backupPath = path.join(config.database.uri, 'backup', `${guildId}.json`)
if (!config.database.uri.startsWith('mongo')) {
const backupPath = path.join(config.database.uri, 'backup', `${guildId}.json`)
if (!fs.existsSync(backupPath)) return
try {
const json = await readFilePromise(backupPath)
const parsed = JSON.parse(json)
if (exports.guildRss.empty(parsed, true)) guildRss = parsed
guildRss = parsed
} catch (err) {
throw err
}
Expand All @@ -171,7 +171,11 @@ exports.guildRss = {
}
}
}
await models.GuildRssBackup().deleteOne({ id: guildId })
if (config.database.uri.startsWith('mongo')) {
await models.GuildRssBackup().deleteOne({ id: guildId })
} else {
fs.unlinkSync(backupPath)
}
return guildRss
},
empty: (guildRss, skipRemoval) => { // Used on the beginning of each cycle to check for empty sources per guild
Expand Down

0 comments on commit 6bc82d4

Please sign in to comment.