fix(@xen-orchestra/fs#write): dont call limited public methods (#4840)

This commit is contained in:
badrAZ 2020-03-03 18:08:56 +01:00 committed by GitHub
parent 2a7f8c5229
commit b244126d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,7 +118,7 @@ export default class RemoteHandlerAbstract {
}
async closeFile(fd: FileDescriptor): Promise<void> {
await timeout.call(this._closeFile(fd.fd), this._timeout)
await this.__closeFile(fd)
}
async createOutputStream(
@ -300,13 +300,8 @@ export default class RemoteHandlerAbstract {
await this._mktree(normalizePath(dir))
}
async openFile(path: string, flags: string): Promise<FileDescriptor> {
path = normalizePath(path)
return {
fd: await timeout.call(this._openFile(path, flags), this._timeout),
path,
}
openFile(path: string, flags: string): Promise<FileDescriptor> {
return this.__openFile(path, flags)
}
async outputFile(
@ -455,6 +450,21 @@ export default class RemoteHandlerAbstract {
await this._writeFile(normalizePath(file), data, { flags })
}
// Methods that can be called by private methods to avoid parallel limit on public methods
async __closeFile(fd: FileDescriptor): Promise<void> {
await timeout.call(this._closeFile(fd.fd), this._timeout)
}
async __openFile(path: string, flags: string): Promise<FileDescriptor> {
path = normalizePath(path)
return {
fd: await timeout.call(this._openFile(path, flags), this._timeout),
path,
}
}
// Methods that can be implemented by inheriting classes
async _closeFile(fd: mixed): Promise<void> {
@ -586,13 +596,13 @@ export default class RemoteHandlerAbstract {
async _write(file: File, buffer: Buffer, position: number): Promise<void> {
const isPath = typeof file === 'string'
if (isPath) {
file = await this.openFile(file, 'r+')
file = await this.__openFile(file, 'r+')
}
try {
return await this._writeFd(file, buffer, position)
} finally {
if (isPath) {
await this.closeFile(file)
await this.__closeFile(file)
}
}
}