@@ -199,6 +199,13 @@ struct GetArgs {
199199 #[ arg( long, value_enum, default_value = "auto" ) ]
200200 format : Format ,
201201
202+ /// Check that the retrieved package matches the existing file at the
203+ /// output path. Output path will not be modified. Program exits with
204+ /// codes similar to diff(1): exits with 1 if there were differences, and
205+ /// 0 means no differences.
206+ #[ arg( long, conflicts_with = "overwrite" ) ]
207+ check : bool ,
208+
202209 /// Overwrite any existing output file.
203210 #[ arg( long) ]
204211 overwrite : bool ,
@@ -371,21 +378,38 @@ impl GetArgs {
371378 } else {
372379 self . output
373380 } ;
374- ensure ! (
375- self . overwrite || !output_path. exists( ) ,
376- "{output_path:?} already exists; you can use '--overwrite' to overwrite it"
377- ) ;
378-
379- if let Some ( wit) = wit {
380- std:: fs:: write ( & output_path, wit)
381- . with_context ( || format ! ( "Failed to write WIT to {output_path:?}" ) ) ?
381+
382+ if self . check {
383+ let existing = tokio:: fs:: read ( & output_path)
384+ . await
385+ . with_context ( || format ! ( "Failed to read {output_path:?}" ) ) ?;
386+ let latest = if let Some ( wit) = wit {
387+ wit. into_bytes ( )
388+ } else {
389+ tokio:: fs:: read ( & tmp_path)
390+ . await
391+ . with_context ( || format ! ( "Failed to read {tmp_path:?}" ) ) ?
392+ } ;
393+ if existing != latest {
394+ anyhow:: bail!( "Differences between retrieved and {output_path:?}" ) ;
395+ }
382396 } else {
383- tmp_path
384- . persist ( & output_path)
385- . with_context ( || format ! ( "Failed to persist WASM to {output_path:?}" ) ) ?
386- }
387- println ! ( "Wrote '{}'" , output_path. display( ) ) ;
397+ ensure ! (
398+ self . overwrite || !output_path. exists( ) ,
399+ "{output_path:?} already exists; you can use '--overwrite' to overwrite it"
400+ ) ;
388401
402+ if let Some ( wit) = wit {
403+ tokio:: fs:: write ( & output_path, wit)
404+ . await
405+ . with_context ( || format ! ( "Failed to write WIT to {output_path:?}" ) ) ?
406+ } else {
407+ tmp_path
408+ . persist ( & output_path)
409+ . with_context ( || format ! ( "Failed to persist WASM to {output_path:?}" ) ) ?
410+ }
411+ println ! ( "Wrote '{}'" , output_path. display( ) ) ;
412+ }
389413 Ok ( ( ) )
390414 }
391415}
0 commit comments