mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
fix: handle BinaryManager removal errors
This commit is contained in:
parent
9a6591fa59
commit
3489feaf67
2 changed files with 30 additions and 2 deletions
|
|
@ -369,14 +369,14 @@ class BinaryManager {
|
||||||
* @param {Binary} binary
|
* @param {Binary} binary
|
||||||
*/
|
*/
|
||||||
async removeBinary(destination, binary) {
|
async removeBinary(destination, binary) {
|
||||||
|
const binaryPath = path.join(destination, binary.fileName)
|
||||||
try {
|
try {
|
||||||
const binaryPath = path.join(destination, binary.fileName)
|
|
||||||
if (await fs.pathExists(binaryPath)) {
|
if (await fs.pathExists(binaryPath)) {
|
||||||
Logger.debug(`[BinaryManager] Removing binary: ${binaryPath}`)
|
Logger.debug(`[BinaryManager] Removing binary: ${binaryPath}`)
|
||||||
await fs.remove(binaryPath)
|
await fs.remove(binaryPath)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error(`[BinaryManager] Error removing binary: ${binaryPath}`)
|
Logger.error(`[BinaryManager] Error removing binary: ${binaryPath}`, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const fs = require('../../../server/libs/fsExtra')
|
||||||
const fileUtils = require('../../../server/utils/fileUtils')
|
const fileUtils = require('../../../server/utils/fileUtils')
|
||||||
const which = require('../../../server/libs/which')
|
const which = require('../../../server/libs/which')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const Logger = require('../../../server/Logger')
|
||||||
const BinaryManager = require('../../../server/managers/BinaryManager')
|
const BinaryManager = require('../../../server/managers/BinaryManager')
|
||||||
const { Binary, ffbinaries } = require('../../../server/managers/BinaryManager')
|
const { Binary, ffbinaries } = require('../../../server/managers/BinaryManager')
|
||||||
|
|
||||||
|
|
@ -203,6 +204,33 @@ describe('BinaryManager', () => {
|
||||||
expect(downloadBinaryStub.calledWith(destination)).to.be.true
|
expect(downloadBinaryStub.calledWith(destination)).to.be.true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('removeBinary', () => {
|
||||||
|
let pathExistsStub
|
||||||
|
let errorStub
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
binaryManager = new BinaryManager()
|
||||||
|
pathExistsStub = sinon.stub(fs, 'pathExists').rejects(new Error('remove failed'))
|
||||||
|
errorStub = sinon.stub(Logger, 'error')
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
pathExistsStub.restore()
|
||||||
|
errorStub.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('logs the resolved binary path when removal fails', async () => {
|
||||||
|
const destination = '/path/to/install'
|
||||||
|
const binary = { fileName: 'ffmpeg' }
|
||||||
|
|
||||||
|
await binaryManager.removeBinary(destination, binary)
|
||||||
|
|
||||||
|
expect(errorStub.calledOnce).to.be.true
|
||||||
|
expect(errorStub.firstCall.args[0]).to.include(path.join(destination, binary.fileName))
|
||||||
|
expect(errorStub.firstCall.args[1]).to.be.an('error')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Binary', () => {
|
describe('Binary', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue