@@ -171,27 +171,16 @@ fn install_one(
171
171
& mut |git| git. read_packages ( ) ,
172
172
) ?
173
173
} 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) ?;
179
175
src. update ( ) . chain_err ( || {
180
176
format_err ! (
181
177
"`{}` is not a crate root; specify a crate to \
182
178
install from crates.io, or use --path or --git to \
183
179
specify an alternate source",
184
- path. display( )
180
+ src . path( ) . display( )
185
181
)
186
182
} ) ?;
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 ( ) ) ?
195
184
} else {
196
185
select_pkg (
197
186
map. load ( source_id) ?,
@@ -419,6 +408,14 @@ fn install_one(
419
408
Ok ( ( ) )
420
409
}
421
410
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
+
422
419
fn select_pkg < ' a , T > (
423
420
mut source : T ,
424
421
name : Option < & str > ,
@@ -720,6 +717,9 @@ pub fn uninstall(
720
717
let scheduled_error = if specs. len ( ) == 1 {
721
718
uninstall_one ( & root, specs[ 0 ] , bins, config) ?;
722
719
false
720
+ } else if specs. len ( ) == 0 {
721
+ uninstall_cwd ( & root, bins, config) ?;
722
+ false
723
723
} else {
724
724
let mut succeeded = vec ! [ ] ;
725
725
let mut failed = vec ! [ ] ;
@@ -769,13 +769,38 @@ pub fn uninstall_one(
769
769
config : & Config ,
770
770
) -> CargoResult < ( ) > {
771
771
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 < ( ) > {
773
799
let mut to_remove = Vec :: new ( ) ;
774
800
{
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 ( ) ) {
777
802
Entry :: Occupied ( e) => e,
778
- Entry :: Vacant ( ..) => panic ! ( "entry not found: {} " , result ) ,
803
+ Entry :: Vacant ( ..) => bail ! ( "package `{}` is not installed " , pkgid ) ,
779
804
} ;
780
805
let dst = crate_metadata. parent ( ) . join ( "bin" ) ;
781
806
for bin in installed. get ( ) {
@@ -800,7 +825,7 @@ pub fn uninstall_one(
800
825
801
826
for bin in bins. iter ( ) {
802
827
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 )
804
829
}
805
830
}
806
831
0 commit comments