fix(fs/Local#lock): never fail on release

Related to zammad#8826

Also, log properly if the log is compromised.
This commit is contained in:
Julien Fontanet 2022-08-10 17:32:36 +02:00
parent d6c3dc87e0
commit a963878af5

View File

@ -2,10 +2,13 @@ import df from '@sindresorhus/df'
import fs from 'fs-extra'
import identity from 'lodash/identity.js'
import lockfile from 'proper-lockfile'
import { createLogger } from '@xen-orchestra/log'
import { fromEvent, retry } from 'promise-toolbox'
import RemoteHandlerAbstract from './abstract'
const { warn } = createLogger('xo:fs:local')
// save current stack trace and add it to any rejected error
//
// This is especially useful when the resolution is separate from the initial
@ -106,8 +109,19 @@ export default class LocalHandler extends RemoteHandlerAbstract {
return this._addSyncStackTrace(fs.readdir(this._getFilePath(dir)))
}
_lock(path) {
return lockfile.lock(this._getFilePath(path))
async _lock(path) {
const release = lockfile.lock(this._getFilePath(path), {
onCompromised: async error => {
warn('lock compromised', { error })
},
})
return async () => {
try {
await release()
} catch (error) {
warn('lock could not be released', { error })
}
}
}
_mkdir(dir, { mode }) {