File tree 1 file changed +12
-3
lines changed 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -281,8 +281,6 @@ export async function download(options: DownloadOptions) {
281
281
const dispatcher = options ?. dispatcher ?? getDefaultAgent ( )
282
282
const expectedTotal = options . expectedTotal
283
283
284
- await mkdir ( dirname ( destination ) , { recursive : true } ) . catch ( ( ) => { } )
285
-
286
284
if ( ! skipPrevalidate && validator ) {
287
285
const error = await validator . validate ( destination , urls [ 0 ] ) . catch ( ( e ) => e )
288
286
if ( ! error ) {
@@ -306,7 +304,8 @@ export async function download(options: DownloadOptions) {
306
304
}
307
305
308
306
const output = pendingFile || destination
309
- const fd = await open ( output , 'w' ) . catch ( ( e ) => {
307
+ await mkdir ( dirname ( destination ) , { recursive : true } ) . catch ( ( ) => { } )
308
+ function assignError ( e : Error ) {
310
309
e . stack = new Error ( ) . stack
311
310
Object . assign ( e , {
312
311
phase : 'open' ,
@@ -315,6 +314,16 @@ export async function download(options: DownloadOptions) {
315
314
destination,
316
315
pendingFile,
317
316
} )
317
+ }
318
+ const fd = await open ( output , 'w' ) . catch ( async ( e ) => {
319
+ if ( e . code === 'ENOENT' ) {
320
+ await mkdir ( dirname ( destination ) , { recursive : true } )
321
+ return await open ( output , 'w' ) . catch ( ( e ) => {
322
+ assignError ( e )
323
+ throw e
324
+ } )
325
+ }
326
+ assignError ( e )
318
327
throw e
319
328
} )
320
329
You can’t perform that action at this time.
0 commit comments