@@ -10,7 +10,9 @@ use reqwest::Url;
1010use crate :: {
1111 config:: { ComputePlatform , Config } ,
1212 cscs:: {
13- api_client:: { CscsApi , FileStat , FileSystemType , Job , JobDetail , PathEntry , S3Upload , System , UserInfo } ,
13+ api_client:: {
14+ CscsApi , FileStat , FileSystemType , Job , JobDetail , PathEntry , PathType , S3Upload , System , UserInfo ,
15+ } ,
1416 oauth2:: {
1517 CLIENT_ID_SECRET_NAME , CLIENT_SECRET_SECRET_NAME , client_credentials_login, finish_cscs_device_login,
1618 start_cscs_device_login,
@@ -115,7 +117,12 @@ pub async fn cscs_job_details(
115117 }
116118}
117119
118- pub async fn cscs_job_log ( job_id : i64 , system : Option < String > , platform : Option < ComputePlatform > ) -> Result < String > {
120+ pub async fn cscs_job_log (
121+ job_id : i64 ,
122+ stderr : bool ,
123+ system : Option < String > ,
124+ platform : Option < ComputePlatform > ,
125+ ) -> Result < String > {
119126 match get_access_token ( ) . await {
120127 Ok ( access_token) => {
121128 let api_client = CscsApi :: new ( access_token. 0 , platform) . unwrap ( ) ;
@@ -125,9 +132,12 @@ pub async fn cscs_job_log(job_id: i64, system: Option<String>, platform: Option<
125132 if job. is_none ( ) {
126133 return Err ( eyre ! ( "couldn't find job {}" , job_id) ) ;
127134 }
128- api_client
129- . tail ( current_system, PathBuf :: from ( job. unwrap ( ) . stdout ) , 100 )
130- . await
135+ let path = if stderr {
136+ PathBuf :: from ( job. unwrap ( ) . stderr )
137+ } else {
138+ PathBuf :: from ( job. unwrap ( ) . stdout )
139+ } ;
140+ api_client. tail ( current_system, path, 100 ) . await
131141 }
132142 Err ( e) => Err ( e) ,
133143 }
@@ -321,6 +331,16 @@ pub async fn cscs_file_upload(
321331 Ok ( access_token) => {
322332 let api_client = CscsApi :: new ( access_token. 0 , platform) . unwrap ( ) ;
323333 let config = Config :: new ( ) . unwrap ( ) ;
334+ let current_system = & system. unwrap_or ( config. cscs . current_system ) ;
335+ let existing = api_client. list_path ( current_system, remote. clone ( ) ) . await ?;
336+ let remote = if !existing. is_empty ( ) {
337+ if existing. len ( ) == 1 && existing[ 0 ] . path_type == PathType :: File {
338+ return Err ( eyre ! ( "remote file already exists" ) ) ;
339+ }
340+ remote. join ( local. file_name ( ) . ok_or ( eyre ! ( "couldn't get filename for local file" ) ) ?)
341+ } else {
342+ remote
343+ } ;
324344
325345 let file_meta = std:: fs:: metadata ( local. clone ( ) ) ?;
326346
@@ -333,15 +353,13 @@ pub async fn cscs_file_upload(
333353 if size < CSCS_MAX_DIRECT_SIZE {
334354 // upload directly
335355 let contents = std:: fs:: read ( local) ?;
336- api_client
337- . upload ( & system. unwrap_or ( config. cscs . current_system ) , remote, contents)
338- . await ?;
356+ api_client. upload ( current_system, remote, contents) . await ?;
339357 Ok ( None )
340358 } else {
341359 // upload via s3
342360 let account = account. or ( config. cscs . account ) ;
343361 let transfer_data = api_client
344- . transfer_upload ( & config . cscs . current_system , account, remote, size as i64 )
362+ . transfer_upload ( current_system, account, remote, size as i64 )
345363 . await ?;
346364
347365 Ok ( Some ( transfer_data) )
0 commit comments