@@ -8,10 +8,9 @@ pub mod unpack;
88
99use crate :: csmrc:: Config ;
1010use crate :: env:: parsing:: env_file:: RobotmkEnv ;
11- use crate :: micromamba:: { self , MicromambaResult , micromamba} ;
11+ use crate :: micromamba:: { MicromambaResult , micromamba} ;
1212
1313use log:: { debug, error, info} ;
14- use std:: fs;
1514use std:: path:: { Component , Path , PathBuf } ;
1615use std:: process:: ExitCode ;
1716
@@ -125,74 +124,6 @@ pub fn run(config: Config, subcommand: Subcommand) -> Result<(), ExitCode> {
125124 Subcommand :: Activate ( args) => activate:: run ( config, args) ,
126125 Subcommand :: Deactivate => deactivate:: run ( ) ,
127126 Subcommand :: Pack ( args) => pack:: run ( config, args) ,
128- Subcommand :: Unpack ( args) => {
129- fn archive_name_to_env_name ( archive_path : & Path ) -> Option < String > {
130- let filename = archive_path. file_name ( ) ?. to_str ( ) ?;
131- filename
132- . strip_suffix ( ".tar.gz" )
133- . or_else ( || filename. strip_suffix ( ".tgz" ) )
134- . map ( String :: from)
135- }
136- let env_name = match args. common . name {
137- Some ( name) => name,
138- None => match archive_name_to_env_name ( & args. archive_path ) {
139- Some ( name) => {
140- info ! (
141- "Using '{}' as environment name, based on archive filename" ,
142- name
143- ) ;
144- name
145- }
146- None => {
147- error ! (
148- "Could not determine environment name from archive filename. Please specify an environment name with --name."
149- ) ;
150- return Err ( ExitCode :: FAILURE ) ;
151- }
152- } ,
153- } ;
154-
155- // TODO: We really need a more generic error type to avoid this kind of mapping everywhere
156- let target_env_path = micromamba:: create_env_dir ( & config, & env_name) . map_err ( |e| {
157- error ! ( "{}" , e) ;
158- ExitCode :: FAILURE
159- } ) ?;
160-
161- // Send the archive to flate2 to decompress and untar
162- info ! (
163- "Unpacking archive '{}' to create environment '{}'" ,
164- args. archive_path. display( ) ,
165- env_name
166- ) ;
167- debug ! ( "Opening '{}' for read" , args. archive_path. display( ) ) ;
168- let archive_file = fs:: File :: open ( & args. archive_path ) . map_err ( |e| {
169- error ! ( "{}" , e) ;
170- ExitCode :: FAILURE
171- } ) ?;
172- let decompressor = flate2:: read:: GzDecoder :: new ( archive_file) ;
173- let mut archive = tar:: Archive :: new ( decompressor) ;
174- archive. unpack ( & target_env_path) . map_err ( |e| {
175- error ! (
176- "Could not unpack archive to '{}': {}" ,
177- target_env_path. display( ) ,
178- e
179- ) ;
180- ExitCode :: FAILURE
181- } ) ?;
182- info ! (
183- "Successfully unpacked environment to '{}'" ,
184- target_env_path. display( )
185- ) ;
186-
187- info ! ( "Running 'conda-unpack' in the new environment to fix paths..." ) ;
188- let result = micromamba (
189- & config,
190- vec ! [ "run" , "--name" , & env_name, "conda-unpack" ] ,
191- config. verbose ,
192- ) ;
193- let rc = result. exit_code ( ) ;
194- dump_micromamba_captured_output_on_error ( & result, rc) ;
195- result. into ( )
196- }
127+ Subcommand :: Unpack ( args) => unpack:: run ( config, args) ,
197128 }
198129}
0 commit comments