@@ -3,6 +3,7 @@ use crate::{
33 types:: { ProcessArgs , ReprocessArgs } ,
44} ;
55use anyhow:: { bail, Result } ;
6+ use dotenvy:: dotenv;
67use libmdrepo:: { common:: file_exists, metadata:: Meta } ;
78use log:: { debug, info} ;
89use std:: {
@@ -13,24 +14,27 @@ use std::{
1314
1415// --------------------------------------------------
1516pub fn reprocess ( args : & ReprocessArgs ) -> Result < ( ) > {
16- let _ = dotenv:: dotenv ( ) ;
17+ dotenv ( ) . ok ( ) ;
1718 let simulation_id = args. simulation_id ;
1819 let mdrepo_id = format ! ( "MDR{simulation_id:08}" ) ;
1920 debug ! ( "Reprocessing simulation ID {mdrepo_id}" ) ;
2021
2122 let data_dir = & args. work_dir . join ( & mdrepo_id) ;
2223 if !data_dir. is_dir ( ) {
23- fs:: create_dir_all ( & args . work_dir ) ?;
24+ fs:: create_dir_all ( & data_dir ) ?;
2425 }
2526
2627 let server = & args. server ;
2728 let irods_dir =
2829 format ! ( "/iplant/home/shared/mdrepo/{server}/release/{mdrepo_id}/original" ) ;
2930 let irods_dir = Path :: new ( & irods_dir) ;
31+ debug ! ( r#"irods_dir = "{}""# , irods_dir. display( ) ) ;
3032
31- let meta_path = data_dir. join ( "mdrepo-metadata.toml" ) ;
32- let meta = Meta :: from_file ( & meta_path) ?;
33+ let meta_filename = "mdrepo-metadata.toml" ;
34+ let meta_local_path = data_dir. join ( meta_filename) ;
35+ irods_fetch ( & irods_dir. join ( meta_filename) , & meta_local_path) ?;
3336
37+ let meta = Meta :: from_file ( & meta_local_path) ?;
3438 for filename in & [
3539 & meta. trajectory_file_name ,
3640 & meta. structure_file_name ,
@@ -67,21 +71,26 @@ pub fn reprocess(args: &ReprocessArgs) -> Result<()> {
6771
6872// --------------------------------------------------
6973fn irods_fetch ( irods_path : & Path , local_path : & PathBuf ) -> Result < ( ) > {
70- if !file_exists ( local_path) {
71- debug ! (
72- r#"Get "{}" -> "{}""# ,
73- irods_path. display( ) ,
74- local_path. display( )
75- ) ;
76- let cmd = Command :: new ( "gocmd" )
77- . args ( [
78- "get" ,
79- irods_path. to_string_lossy ( ) . as_ref ( ) ,
80- local_path. to_string_lossy ( ) . as_ref ( ) ,
81- ] )
82- . output ( ) ?;
83- if !cmd. status . success ( ) {
84- bail ! ( str :: from_utf8( & cmd. stderr) ?. to_string( ) ) ;
74+ debug ! (
75+ r#"Get "{}" -> "{}""# ,
76+ irods_path. display( ) ,
77+ local_path. display( )
78+ ) ;
79+
80+ if file_exists ( local_path) {
81+ debug ! ( "Already downloaded" ) ;
82+ } else {
83+ let mut cmd = Command :: new ( "gocmd" ) ;
84+ cmd. args ( [
85+ "get" ,
86+ irods_path. to_string_lossy ( ) . as_ref ( ) ,
87+ local_path. to_string_lossy ( ) . as_ref ( ) ,
88+ ] ) ;
89+ debug ! ( "Running {cmd:?}" ) ;
90+ let output = cmd. output ( ) ?;
91+
92+ if !output. status . success ( ) {
93+ bail ! ( str :: from_utf8( & output. stderr) ?. to_string( ) ) ;
8594 }
8695 }
8796 Ok ( ( ) )
0 commit comments