@@ -319,14 +319,12 @@ fn verify_dependencies(
319
319
Ok ( ( ) )
320
320
}
321
321
322
- fn transmit (
322
+ pub ( crate ) fn prepare_transmit (
323
323
gctx : & GlobalContext ,
324
324
pkg : & Package ,
325
- tarball : & File ,
326
- registry : & mut Registry ,
327
325
registry_id : SourceId ,
328
- dry_run : bool ,
329
- ) -> CargoResult < ( ) > {
326
+ require_readme_and_license : bool ,
327
+ ) -> CargoResult < NewCrate > {
330
328
let deps = pkg
331
329
. dependencies ( )
332
330
. iter ( )
@@ -401,19 +399,20 @@ fn transmit(
401
399
paths:: read ( & pkg. root ( ) . join ( readme) )
402
400
. with_context ( || format ! ( "failed to read `readme` file for package `{}`" , pkg) )
403
401
} )
404
- . transpose ( ) ?;
402
+ . transpose ( )
403
+ . or_else ( |e| {
404
+ if require_readme_and_license {
405
+ Err ( e)
406
+ } else {
407
+ Ok ( None )
408
+ }
409
+ } ) ?;
405
410
if let Some ( ref file) = * license_file {
406
- if !pkg. root ( ) . join ( file) . exists ( ) {
411
+ if require_readme_and_license && !pkg. root ( ) . join ( file) . exists ( ) {
407
412
bail ! ( "the license file `{}` does not exist" , file)
408
413
}
409
414
}
410
415
411
- // Do not upload if performing a dry run
412
- if dry_run {
413
- gctx. shell ( ) . warn ( "aborting upload due to dry run" ) ?;
414
- return Ok ( ( ) ) ;
415
- }
416
-
417
416
let deps_set = deps
418
417
. iter ( )
419
418
. map ( |dep| dep. name . clone ( ) )
@@ -445,30 +444,46 @@ fn transmit(
445
444
None => BTreeMap :: new ( ) ,
446
445
} ;
447
446
447
+ Ok ( NewCrate {
448
+ name : pkg. name ( ) . to_string ( ) ,
449
+ vers : pkg. version ( ) . to_string ( ) ,
450
+ deps,
451
+ features : string_features,
452
+ authors : authors. clone ( ) ,
453
+ description : description. clone ( ) ,
454
+ homepage : homepage. clone ( ) ,
455
+ documentation : documentation. clone ( ) ,
456
+ keywords : keywords. clone ( ) ,
457
+ categories : categories. clone ( ) ,
458
+ readme : readme_content,
459
+ readme_file : readme. clone ( ) ,
460
+ repository : repository. clone ( ) ,
461
+ license : license. clone ( ) ,
462
+ license_file : license_file. clone ( ) ,
463
+ badges : badges. clone ( ) ,
464
+ links : links. clone ( ) ,
465
+ rust_version,
466
+ } )
467
+ }
468
+
469
+ fn transmit (
470
+ gctx : & GlobalContext ,
471
+ pkg : & Package ,
472
+ tarball : & File ,
473
+ registry : & mut Registry ,
474
+ registry_id : SourceId ,
475
+ dry_run : bool ,
476
+ ) -> CargoResult < ( ) > {
477
+ let new_crate = prepare_transmit ( gctx, pkg, registry_id, true ) ?;
478
+
479
+ // Do not upload if performing a dry run
480
+ if dry_run {
481
+ gctx. shell ( ) . warn ( "aborting upload due to dry run" ) ?;
482
+ return Ok ( ( ) ) ;
483
+ }
484
+
448
485
let warnings = registry
449
- . publish (
450
- & NewCrate {
451
- name : pkg. name ( ) . to_string ( ) ,
452
- vers : pkg. version ( ) . to_string ( ) ,
453
- deps,
454
- features : string_features,
455
- authors : authors. clone ( ) ,
456
- description : description. clone ( ) ,
457
- homepage : homepage. clone ( ) ,
458
- documentation : documentation. clone ( ) ,
459
- keywords : keywords. clone ( ) ,
460
- categories : categories. clone ( ) ,
461
- readme : readme_content,
462
- readme_file : readme. clone ( ) ,
463
- repository : repository. clone ( ) ,
464
- license : license. clone ( ) ,
465
- license_file : license_file. clone ( ) ,
466
- badges : badges. clone ( ) ,
467
- links : links. clone ( ) ,
468
- rust_version,
469
- } ,
470
- tarball,
471
- )
486
+ . publish ( & new_crate, tarball)
472
487
. with_context ( || format ! ( "failed to publish to registry at {}" , registry. host( ) ) ) ?;
473
488
474
489
if !warnings. invalid_categories . is_empty ( ) {
0 commit comments