feat(fs/abstract#list): ignore ENOENT error
This commit is contained in:
parent
cfaf336597
commit
48af5c7ed6
@ -242,7 +242,8 @@ export default class RemoteHandlerAbstract {
|
||||
return timeout.call(this._getSize(typeof file === 'string' ? normalizePath(file) : file), this._timeout)
|
||||
}
|
||||
|
||||
async list(dir, { filter, prependDir = false } = {}) {
|
||||
async list(dir, { filter, ignoreEnoentError: ignoreMissing = false, prependDir = false } = {}) {
|
||||
try {
|
||||
const virtualDir = normalizePath(dir)
|
||||
dir = normalizePath(dir)
|
||||
|
||||
@ -258,6 +259,12 @@ export default class RemoteHandlerAbstract {
|
||||
}
|
||||
|
||||
return entries
|
||||
} catch (error) {
|
||||
if (ignoreMissing && error?.code === 'ENOENT') {
|
||||
return []
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async lock(path) {
|
||||
|
@ -133,6 +133,14 @@ handlers.forEach(url => {
|
||||
await handler.outputFile('dir/file', '')
|
||||
expect(await handler.list('dir', { prependDir: true })).toEqual(['/dir/file'])
|
||||
})
|
||||
|
||||
it.only('throws ENOENT if no such directory', async () => {
|
||||
expect((await rejectionOf(handler.list('dir'))).code).toBe('ENOENT')
|
||||
})
|
||||
|
||||
it.only('can returns empty for missing directory', async () => {
|
||||
expect(await handler.list('dir', { ignoreMissing: true })).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('#mkdir()', () => {
|
||||
|
@ -27,3 +27,5 @@
|
||||
> - major: if the change breaks compatibility
|
||||
>
|
||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||
|
||||
- @xen-orchestra/fs minor
|
||||
|
Loading…
Reference in New Issue
Block a user