@@ -18,11 +18,12 @@ use crate::{
1818/// Returns the path to the installed package and a bool indicating
1919/// if the package was downloaded.
2020pub fn install < S , C > (
21+ ws : & Path ,
2122 pkg : S ,
2223 version : & Version ,
2324 index : Option < & Index > ,
2425 progress_callback : C ,
25- ) -> Result < ( PathBuf , bool ) >
26+ ) -> Result < ( PathBuf , PathBuf , bool ) >
2627where
2728 S : AsRef < str > ,
2829 C : FnMut ( git2:: Progress < ' _ > ) ,
@@ -49,29 +50,31 @@ where
4950 . with_context ( || format ! ( "{} is not a version of '{}'" , version, pkg) ) ?;
5051
5152 let ident = format ! ( "{}-{}" , pkg, version) ;
52- let path = paths:: pkg ( "." , & ident) ;
53+ let path = paths:: pkg ( ws , Path :: new ( & ident) ) ;
5354 if path. exists ( ) {
54- return Ok ( ( path, false ) ) ;
55+ return Ok ( ( paths :: pkg ( "." , & ident ) , path, false ) ) ;
5556 }
5657
57- let ( path, _) = install_git (
58+ let ( relative_path, full_path, _) = install_git (
59+ ws,
5860 & entry. url ,
5961 Some ( & metadata. rev ) ,
6062 Some ( & ident) ,
6163 progress_callback,
6264 ) ?;
6365
64- Ok ( ( path , true ) )
66+ Ok ( ( relative_path , full_path , true ) )
6567}
6668
67- /// Returns the path to the installed package and the revision
68- /// that was checked out.
69+ /// Returns the path to the installed package, first relative to the workspace,
70+ /// then relative to the working directory. Last is the revision that was checked out.
6971pub fn install_git < C > (
72+ ws : & Path ,
7073 url : & Url ,
7174 rev : Option < & str > ,
7275 pkg_ident : Option < & String > ,
7376 mut progress_callback : C ,
74- ) -> Result < ( PathBuf , String ) >
77+ ) -> Result < ( PathBuf , PathBuf , String ) >
7578where
7679 C : FnMut ( git2:: Progress < ' _ > ) ,
7780{
@@ -121,26 +124,28 @@ where
121124 // Dropping the repository gives us access to the directory
122125 }
123126
124- let path = pkg_ident
125- . map ( |ident| paths:: pkg ( ". " , ident) )
127+ let relative_path = pkg_ident
128+ . map ( |ident| paths:: pkg ( "" , ident) )
126129 . unwrap_or_else ( || {
127130 let mut pkg = url. host ( ) . unwrap ( ) . to_string ( ) ;
128131 pkg. push_str ( & url. path ( ) . replace ( '/' , "-" ) . replace ( ".git" , "" ) ) ;
129132 pkg = format ! ( "{}-{}" , pkg, checkout_rev) ;
130- paths:: pkg ( ". " , & pkg)
133+ paths:: pkg ( "" , & pkg)
131134 } ) ;
132135
133- if path. exists ( ) {
134- return Ok ( ( path, checkout_rev) ) ;
136+ let full_path = ws. join ( & relative_path) ;
137+
138+ if full_path. exists ( ) {
139+ return Ok ( ( relative_path, full_path, checkout_rev) ) ;
135140 }
136141
137- fs:: rename ( paths:: tmp ( ) , & path ) . context ( "Failed to move tmp folder" ) ?;
142+ fs:: rename ( paths:: tmp ( ) , & full_path ) . context ( "Failed to move tmp folder" ) ?;
138143
139144 if pkg_ident. is_some ( ) {
140- prepare_pkg ( & path , pkg_ident. map ( String :: as_str) ) ?;
145+ prepare_pkg ( & full_path , pkg_ident. map ( String :: as_str) ) ?;
141146 }
142147
143- Ok ( ( path , checkout_rev) )
148+ Ok ( ( relative_path , full_path , checkout_rev) )
144149}
145150
146151pub fn prepare_pkg ( path : & Path , ident : Option < & str > ) -> Result < ( ) > {
0 commit comments