@@ -171,27 +171,16 @@ fn install_one(
171171 & mut |git| git. read_packages ( ) ,
172172 ) ?
173173 } else if source_id. is_path ( ) {
174- let path = source_id
175- . url ( )
176- . to_file_path ( )
177- . map_err ( |( ) | format_err ! ( "path sources must have a valid path" ) ) ?;
178- let mut src = PathSource :: new ( & path, source_id, config) ;
174+ let mut src = path_source ( source_id, config) ?;
179175 src. update ( ) . chain_err ( || {
180176 format_err ! (
181177 "`{}` is not a crate root; specify a crate to \
182178 install from crates.io, or use --path or --git to \
183179 specify an alternate source",
184- path. display( )
180+ src . path( ) . display( )
185181 )
186182 } ) ?;
187- select_pkg (
188- PathSource :: new ( & path, source_id, config) ,
189- krate,
190- vers,
191- config,
192- is_first_install,
193- & mut |path| path. read_packages ( ) ,
194- ) ?
183+ select_pkg ( src, krate, vers, config, false , & mut |path| path. read_packages ( ) ) ?
195184 } else {
196185 select_pkg (
197186 map. load ( source_id) ?,
@@ -419,6 +408,14 @@ fn install_one(
419408 Ok ( ( ) )
420409}
421410
411+ fn path_source < ' a > ( source_id : & SourceId , config : & ' a Config ) -> CargoResult < PathSource < ' a > > {
412+ let path = source_id
413+ . url ( )
414+ . to_file_path ( )
415+ . map_err ( |( ) | format_err ! ( "path sources must have a valid path" ) ) ?;
416+ Ok ( PathSource :: new ( & path, source_id, config) )
417+ }
418+
422419fn select_pkg < ' a , T > (
423420 mut source : T ,
424421 name : Option < & str > ,
@@ -720,6 +717,9 @@ pub fn uninstall(
720717 let scheduled_error = if specs. len ( ) == 1 {
721718 uninstall_one ( & root, specs[ 0 ] , bins, config) ?;
722719 false
720+ } else if specs. len ( ) == 0 {
721+ uninstall_cwd ( & root, bins, config) ?;
722+ false
723723 } else {
724724 let mut succeeded = vec ! [ ] ;
725725 let mut failed = vec ! [ ] ;
@@ -769,13 +769,38 @@ pub fn uninstall_one(
769769 config : & Config ,
770770) -> CargoResult < ( ) > {
771771 let crate_metadata = metadata ( config, root) ?;
772- let mut metadata = read_crate_list ( & crate_metadata) ?;
772+ let metadata = read_crate_list ( & crate_metadata) ?;
773+ let pkgid = PackageIdSpec :: query_str ( spec, metadata. v1 . keys ( ) ) ?. clone ( ) ;
774+ uninstall_pkgid ( crate_metadata, metadata, & pkgid, bins, config)
775+ }
776+
777+ fn uninstall_cwd (
778+ root : & Filesystem ,
779+ bins : & [ String ] ,
780+ config : & Config ,
781+ ) -> CargoResult < ( ) > {
782+ let crate_metadata = metadata ( config, root) ?;
783+ let metadata = read_crate_list ( & crate_metadata) ?;
784+ let source_id = SourceId :: for_path ( config. cwd ( ) ) ?;
785+ let src = path_source ( & source_id, config) ?;
786+ let ( pkg, _source) =
787+ select_pkg ( src, None , None , config, true , & mut |path| path. read_packages ( ) ) ?;
788+ let pkgid = pkg. package_id ( ) ;
789+ uninstall_pkgid ( crate_metadata, metadata, pkgid, bins, config)
790+ }
791+
792+ fn uninstall_pkgid (
793+ crate_metadata : FileLock ,
794+ mut metadata : CrateListingV1 ,
795+ pkgid : & PackageId ,
796+ bins : & [ String ] ,
797+ config : & Config ,
798+ ) -> CargoResult < ( ) > {
773799 let mut to_remove = Vec :: new ( ) ;
774800 {
775- let result = PackageIdSpec :: query_str ( spec, metadata. v1 . keys ( ) ) ?. clone ( ) ;
776- let mut installed = match metadata. v1 . entry ( result. clone ( ) ) {
801+ let mut installed = match metadata. v1 . entry ( pkgid. clone ( ) ) {
777802 Entry :: Occupied ( e) => e,
778- Entry :: Vacant ( ..) => panic ! ( "entry not found: {} " , result ) ,
803+ Entry :: Vacant ( ..) => bail ! ( "package `{}` is not installed " , pkgid ) ,
779804 } ;
780805 let dst = crate_metadata. parent ( ) . join ( "bin" ) ;
781806 for bin in installed. get ( ) {
@@ -800,7 +825,7 @@ pub fn uninstall_one(
800825
801826 for bin in bins. iter ( ) {
802827 if !installed. get ( ) . contains ( bin) {
803- bail ! ( "binary `{}` not installed as part of `{}`" , bin, result )
828+ bail ! ( "binary `{}` not installed as part of `{}`" , bin, pkgid )
804829 }
805830 }
806831
0 commit comments