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:
parent
d6c3dc87e0
commit
a963878af5
@ -2,10 +2,13 @@ import df from '@sindresorhus/df'
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import identity from 'lodash/identity.js'
|
import identity from 'lodash/identity.js'
|
||||||
import lockfile from 'proper-lockfile'
|
import lockfile from 'proper-lockfile'
|
||||||
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { fromEvent, retry } from 'promise-toolbox'
|
import { fromEvent, retry } from 'promise-toolbox'
|
||||||
|
|
||||||
import RemoteHandlerAbstract from './abstract'
|
import RemoteHandlerAbstract from './abstract'
|
||||||
|
|
||||||
|
const { warn } = createLogger('xo:fs:local')
|
||||||
|
|
||||||
// save current stack trace and add it to any rejected error
|
// save current stack trace and add it to any rejected error
|
||||||
//
|
//
|
||||||
// This is especially useful when the resolution is separate from the initial
|
// 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)))
|
return this._addSyncStackTrace(fs.readdir(this._getFilePath(dir)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_lock(path) {
|
async _lock(path) {
|
||||||
return lockfile.lock(this._getFilePath(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 }) {
|
_mkdir(dir, { mode }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user