@@ -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) ?,
@@ -418,6 +407,14 @@ fn install_one(
418
407
Ok ( ( ) )
419
408
}
420
409
410
+ fn path_source < ' a > ( source_id : & SourceId , config : & ' a Config ) -> CargoResult < PathSource < ' a > > {
411
+ let path = source_id
412
+ . url ( )
413
+ . to_file_path ( )
414
+ . map_err ( |( ) | format_err ! ( "path sources must have a valid path" ) ) ?;
415
+ Ok ( PathSource :: new ( & path, source_id, config) )
416
+ }
417
+
421
418
fn select_pkg < ' a , T > (
422
419
mut source : T ,
423
420
name : Option < & str > ,
@@ -719,6 +716,9 @@ pub fn uninstall(
719
716
let scheduled_error = if specs. len ( ) == 1 {
720
717
uninstall_one ( & root, specs[ 0 ] , bins, config) ?;
721
718
false
719
+ } else if specs. len ( ) == 0 {
720
+ uninstall_cwd ( & root, bins, config) ?;
721
+ false
722
722
} else {
723
723
let mut succeeded = vec ! [ ] ;
724
724
let mut failed = vec ! [ ] ;
@@ -768,13 +768,38 @@ pub fn uninstall_one(
768
768
config : & Config ,
769
769
) -> CargoResult < ( ) > {
770
770
let crate_metadata = metadata ( config, root) ?;
771
- let mut metadata = read_crate_list ( & crate_metadata) ?;
771
+ let metadata = read_crate_list ( & crate_metadata) ?;
772
+ let pkgid = PackageIdSpec :: query_str ( spec, metadata. v1 . keys ( ) ) ?. clone ( ) ;
773
+ uninstall_pkgid ( crate_metadata, metadata, & pkgid, bins, config)
774
+ }
775
+
776
+ fn uninstall_cwd (
777
+ root : & Filesystem ,
778
+ bins : & [ String ] ,
779
+ config : & Config ,
780
+ ) -> CargoResult < ( ) > {
781
+ let crate_metadata = metadata ( config, root) ?;
782
+ let metadata = read_crate_list ( & crate_metadata) ?;
783
+ let source_id = SourceId :: for_path ( config. cwd ( ) ) ?;
784
+ let src = path_source ( & source_id, config) ?;
785
+ let ( pkg, _source) =
786
+ select_pkg ( src, None , None , config, true , & mut |path| path. read_packages ( ) ) ?;
787
+ let pkgid = pkg. package_id ( ) ;
788
+ uninstall_pkgid ( crate_metadata, metadata, pkgid, bins, config)
789
+ }
790
+
791
+ fn uninstall_pkgid (
792
+ crate_metadata : FileLock ,
793
+ mut metadata : CrateListingV1 ,
794
+ pkgid : & PackageId ,
795
+ bins : & [ String ] ,
796
+ config : & Config ,
797
+ ) -> CargoResult < ( ) > {
772
798
let mut to_remove = Vec :: new ( ) ;
773
799
{
774
- let result = PackageIdSpec :: query_str ( spec, metadata. v1 . keys ( ) ) ?. clone ( ) ;
775
- let mut installed = match metadata. v1 . entry ( result. clone ( ) ) {
800
+ let mut installed = match metadata. v1 . entry ( pkgid. clone ( ) ) {
776
801
Entry :: Occupied ( e) => e,
777
- Entry :: Vacant ( ..) => panic ! ( "entry not found: {} " , result ) ,
802
+ Entry :: Vacant ( ..) => bail ! ( "package `{}` is not installed " , pkgid ) ,
778
803
} ;
779
804
let dst = crate_metadata. parent ( ) . join ( "bin" ) ;
780
805
for bin in installed. get ( ) {
@@ -799,7 +824,7 @@ pub fn uninstall_one(
799
824
800
825
for bin in bins. iter ( ) {
801
826
if !installed. get ( ) . contains ( bin) {
802
- bail ! ( "binary `{}` not installed as part of `{}`" , bin, result )
827
+ bail ! ( "binary `{}` not installed as part of `{}`" , bin, pkgid )
803
828
}
804
829
}
805
830
0 commit comments