@@ -77,6 +77,18 @@ pub(crate) fn create(
7777 base_python. display( )
7878 ) ;
7979
80+ // Extract the prompt and compute the absolute path prior to validating the location; otherwise,
81+ // we risk deleting (and recreating) the current working directory, which would cause the `CWD`
82+ // queries to fail.
83+ let prompt = match prompt {
84+ Prompt :: CurrentDirectoryName => CWD
85+ . file_name ( )
86+ . map ( |name| name. to_string_lossy ( ) . to_string ( ) ) ,
87+ Prompt :: Static ( value) => Some ( value) ,
88+ Prompt :: None => None ,
89+ } ;
90+ let absolute = std:: path:: absolute ( location) ?;
91+
8092 // Validate the existing location.
8193 match location. metadata ( ) {
8294 Ok ( metadata) if metadata. is_file ( ) => {
@@ -172,7 +184,8 @@ pub(crate) fn create(
172184 Err ( err) => return Err ( Error :: Io ( err) ) ,
173185 }
174186
175- let location = std:: path:: absolute ( location) ?;
187+ // Use the absolute path for all further operations.
188+ let location = absolute;
176189
177190 let bin_name = if cfg ! ( unix) {
178191 "bin"
@@ -182,13 +195,6 @@ pub(crate) fn create(
182195 unimplemented ! ( "Only Windows and Unix are supported" )
183196 } ;
184197 let scripts = location. join ( & interpreter. virtualenv ( ) . scripts ) ;
185- let prompt = match prompt {
186- Prompt :: CurrentDirectoryName => CWD
187- . file_name ( )
188- . map ( |name| name. to_string_lossy ( ) . to_string ( ) ) ,
189- Prompt :: Static ( value) => Some ( value) ,
190- Prompt :: None => None ,
191- } ;
192198
193199 // Add the CACHEDIR.TAG.
194200 cachedir:: ensure_tag ( & location) ?;
0 commit comments