@@ -16,6 +16,7 @@ use capacity_builder::BytesAppendable;
16
16
use deno_ast:: MediaType ;
17
17
use deno_ast:: ModuleKind ;
18
18
use deno_ast:: ModuleSpecifier ;
19
+ use deno_cache_dir:: CACHE_PERM ;
19
20
use deno_core:: anyhow:: bail;
20
21
use deno_core:: anyhow:: Context ;
21
22
use deno_core:: error:: AnyError ;
@@ -46,6 +47,7 @@ use deno_lib::util::hash::FastInsecureHasher;
46
47
use deno_lib:: version:: DENO_VERSION_INFO ;
47
48
use deno_npm:: resolution:: SerializedNpmResolutionSnapshot ;
48
49
use deno_npm:: NpmSystemInfo ;
50
+ use deno_path_util:: fs:: atomic_write_file_with_retries;
49
51
use deno_path_util:: url_from_directory_path;
50
52
use deno_path_util:: url_to_file_path;
51
53
use deno_resolver:: workspace:: WorkspaceResolver ;
@@ -285,17 +287,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
285
287
let download_directory = self . deno_dir . dl_folder_path ( ) ;
286
288
let binary_path = download_directory. join ( & binary_path_suffix) ;
287
289
288
- if !binary_path. exists ( ) {
289
- self
290
- . download_base_binary ( & download_directory, & binary_path_suffix)
291
- . await
292
- . context ( "Setting up base binary." ) ?;
293
- }
294
-
295
290
let read_file = |path : & Path | -> Result < Vec < u8 > , AnyError > {
296
291
std:: fs:: read ( path) . with_context ( || format ! ( "Reading {}" , path. display( ) ) )
297
292
} ;
298
- let archive_data = read_file ( & binary_path) ?;
293
+ let archive_data = if binary_path. exists ( ) {
294
+ read_file ( & binary_path) ?
295
+ } else {
296
+ self
297
+ . download_base_binary ( & binary_path, & binary_path_suffix)
298
+ . await
299
+ . context ( "Setting up base binary." ) ?
300
+ } ;
299
301
let temp_dir = tempfile:: TempDir :: new ( ) ?;
300
302
let base_binary_path = archive:: unpack_into_dir ( archive:: UnpackArgs {
301
303
exe_name : "denort" ,
@@ -311,9 +313,9 @@ impl<'a> DenoCompileBinaryWriter<'a> {
311
313
312
314
async fn download_base_binary (
313
315
& self ,
314
- output_directory : & Path ,
316
+ output_path : & Path ,
315
317
binary_path_suffix : & str ,
316
- ) -> Result < ( ) , AnyError > {
318
+ ) -> Result < Vec < u8 > , AnyError > {
317
319
let download_url = format ! ( "https://dl.deno.land/{binary_path_suffix}" ) ;
318
320
let maybe_bytes = {
319
321
let progress_bars = ProgressBar :: new ( ProgressBarStyle :: DownloadBars ) ;
@@ -340,12 +342,15 @@ impl<'a> DenoCompileBinaryWriter<'a> {
340
342
std:: fs:: create_dir_all ( dir)
341
343
. with_context ( || format ! ( "Creating {}" , dir. display( ) ) )
342
344
} ;
343
- create_dir_all ( output_directory) ?;
344
- let output_path = output_directory. join ( binary_path_suffix) ;
345
345
create_dir_all ( output_path. parent ( ) . unwrap ( ) ) ?;
346
- std:: fs:: write ( & output_path, bytes)
347
- . with_context ( || format ! ( "Writing {}" , output_path. display( ) ) ) ?;
348
- Ok ( ( ) )
346
+ atomic_write_file_with_retries (
347
+ & CliSys :: default ( ) ,
348
+ output_path,
349
+ & bytes,
350
+ CACHE_PERM ,
351
+ )
352
+ . with_context ( || format ! ( "Writing {}" , output_path. display( ) ) ) ?;
353
+ Ok ( bytes)
349
354
}
350
355
351
356
/// This functions creates a standalone deno binary by appending a bundle
0 commit comments