(
source: MaterializeInstallSource,
options?: { signal?: AbortSignal; downloadTimeoutMs?: number },
)
| 86 | } |
| 87 | |
| 88 | async function materializeLocalSource( |
| 89 | source: MaterializeInstallSource, |
| 90 | options?: { signal?: AbortSignal; downloadTimeoutMs?: number }, |
| 91 | ): Promise<MaterializeLocalSourceResult> { |
| 92 | if (source.kind === 'path') { |
| 93 | return { |
| 94 | localPath: expandSourcePath(source.path), |
| 95 | cleanup: async () => {}, |
| 96 | }; |
| 97 | } |
| 98 | |
| 99 | const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'agent-device-source-')); |
| 100 | try { |
| 101 | const downloadedPath = await downloadToTempFile(tempDir, source.url, source.headers, options); |
| 102 | return { |
| 103 | localPath: downloadedPath, |
| 104 | cleanup: async () => { |
| 105 | await fs.rm(tempDir, { recursive: true, force: true }); |
| 106 | }, |
| 107 | }; |
| 108 | } catch (error) { |
| 109 | await fs.rm(tempDir, { recursive: true, force: true }); |
| 110 | throw error; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // fallow-ignore-next-line complexity |
| 115 | async function downloadToTempFile( |
no test coverage detected