feat(fs/abstract#list): ignore ENOENT error
This commit is contained in:
parent
cfaf336597
commit
48af5c7ed6
@ -242,22 +242,29 @@ export default class RemoteHandlerAbstract {
|
|||||||
return timeout.call(this._getSize(typeof file === 'string' ? normalizePath(file) : file), this._timeout)
|
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 } = {}) {
|
||||||
const virtualDir = normalizePath(dir)
|
try {
|
||||||
dir = normalizePath(dir)
|
const virtualDir = normalizePath(dir)
|
||||||
|
dir = normalizePath(dir)
|
||||||
|
|
||||||
let entries = await timeout.call(this._list(dir), this._timeout)
|
let entries = await timeout.call(this._list(dir), this._timeout)
|
||||||
if (filter !== undefined) {
|
if (filter !== undefined) {
|
||||||
entries = entries.filter(filter)
|
entries = entries.filter(filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prependDir) {
|
||||||
|
entries.forEach((entry, i) => {
|
||||||
|
entries[i] = virtualDir + '/' + entry
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries
|
||||||
|
} catch (error) {
|
||||||
|
if (ignoreMissing && error?.code === 'ENOENT') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prependDir) {
|
|
||||||
entries.forEach((entry, i) => {
|
|
||||||
entries[i] = virtualDir + '/' + entry
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async lock(path) {
|
async lock(path) {
|
||||||
|
@ -133,6 +133,14 @@ handlers.forEach(url => {
|
|||||||
await handler.outputFile('dir/file', '')
|
await handler.outputFile('dir/file', '')
|
||||||
expect(await handler.list('dir', { prependDir: true })).toEqual(['/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()', () => {
|
describe('#mkdir()', () => {
|
||||||
|
@ -27,3 +27,5 @@
|
|||||||
> - major: if the change breaks compatibility
|
> - major: if the change breaks compatibility
|
||||||
>
|
>
|
||||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||||
|
|
||||||
|
- @xen-orchestra/fs minor
|
||||||
|
Loading…
Reference in New Issue
Block a user