Write a sentinel and read it back; throws unless the round-trip matches.
(
name: string,
path: string,
marker: string,
signal?: AbortSignal,
)
| 472 | |
| 473 | /** Write a sentinel and read it back; throws unless the round-trip matches. */ |
| 474 | private async probeReadWrite( |
| 475 | name: string, |
| 476 | path: string, |
| 477 | marker: string, |
| 478 | signal?: AbortSignal, |
| 479 | ): Promise<void> { |
| 480 | const attemptSignal = signal |
| 481 | ? AbortSignal.any([signal, AbortSignal.timeout(8000)]) |
| 482 | : AbortSignal.timeout(8000) |
| 483 | const writeUrl = this.spritePath( |
| 484 | name, |
| 485 | `/fs/write?path=${encodeURIComponent(path)}`, |
| 486 | ) |
| 487 | const writeRes = await fetch(writeUrl, { |
| 488 | method: 'PUT', |
| 489 | headers: this.headers({ 'content-type': 'application/octet-stream' }), |
| 490 | body: new TextEncoder().encode(marker), |
| 491 | signal: attemptSignal, |
| 492 | }) |
| 493 | await writeRes.body?.cancel() |
| 494 | if (!writeRes.ok) throw new Error(`probe write HTTP ${writeRes.status}`) |
| 495 | |
| 496 | const readUrl = this.spritePath( |
| 497 | name, |
| 498 | `/fs/read?path=${encodeURIComponent(path)}`, |
| 499 | ) |
| 500 | const readRes = await fetch(readUrl, { |
| 501 | method: 'GET', |
| 502 | headers: this.headers(), |
| 503 | signal: attemptSignal, |
| 504 | }) |
| 505 | if (!readRes.ok) { |
| 506 | await readRes.body?.cancel() |
| 507 | throw new Error(`probe read HTTP ${readRes.status}`) |
| 508 | } |
| 509 | if ((await readRes.text()) !== marker) { |
| 510 | throw new Error('probe read mismatch') |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | private async deleteSentinel(name: string, path: string): Promise<void> { |
| 515 | const res = await fetch( |
no test coverage detected