@@ -18,8 +18,8 @@ use crate::{
1818 cscs:: {
1919 api_client:: types:: { JobStatus , PathEntry , PathType } ,
2020 handlers:: {
21- cscs_file_download, cscs_file_list, cscs_job_cancel, cscs_job_details, cscs_job_list, cscs_job_log ,
22- cscs_stat_path, cscs_system_list, cscs_user_info,
21+ cscs_file_delete , cscs_file_download, cscs_file_list, cscs_job_cancel, cscs_job_details, cscs_job_list,
22+ cscs_job_log , cscs_stat_path, cscs_system_list, cscs_user_info,
2323 } ,
2424 oauth2:: { ACCESS_TOKEN_SECRET_NAME , REFRESH_TOKEN_SECRET_NAME , finish_cscs_device_login} ,
2525 } ,
@@ -221,9 +221,11 @@ impl PollAsync<UserEvent> for AsyncJobLogPort {
221221 }
222222}
223223
224+ #[ derive( Debug ) ]
224225pub enum BackgroundTask {
225226 ListPaths ( PathBuf ) ,
226227 DownloadFile ( PathBuf , PathBuf ) ,
228+ DeleteFile ( String ) ,
227229 GetJobDetails ( usize ) ,
228230 CancelJob ( usize ) ,
229231}
@@ -350,6 +352,16 @@ async fn download_file(
350352 ) ) ) ) ) ,
351353 }
352354}
355+ async fn delete_file ( id : String ) -> Result < Option < Event < UserEvent > > > {
356+ let remote = PathBuf :: from ( id. clone ( ) ) ;
357+ match cscs_file_delete ( remote, None , None ) . await {
358+ Ok ( ( ) ) => Ok ( Some ( Event :: User ( UserEvent :: File ( FileEvent :: DeleteSuccessful ( id) ) ) ) ) ,
359+ Err ( e) => Ok ( Some ( Event :: User ( UserEvent :: Error ( format ! (
360+ "{:?}" ,
361+ Err :: <( ) , Report >( e) . wrap_err( "couldn't delete path" )
362+ ) ) ) ) ) ,
363+ }
364+ }
353365#[ tuirealm:: async_trait]
354366impl PollAsync < UserEvent > for AsyncBackgroundTaskPort {
355367 async fn poll ( & mut self ) -> ListenerResult < Option < Event < UserEvent > > > {
@@ -373,6 +385,13 @@ impl PollAsync<UserEvent> for AsyncBackgroundTaskPort {
373385 Err :: <( ) , Report >( e) . wrap_err( "couldn't download file" )
374386 ) ) ) ) ) ,
375387 } ,
388+ BackgroundTask :: DeleteFile ( remote) => match delete_file ( remote) . await {
389+ Ok ( event) => Ok ( event) ,
390+ Err ( e) => Ok ( Some ( Event :: User ( UserEvent :: Error ( format ! (
391+ "{:?}" ,
392+ Err :: <( ) , Report >( e) . wrap_err( "couldn't delete file" )
393+ ) ) ) ) ) ,
394+ } ,
376395 BackgroundTask :: GetJobDetails ( job_id) => match cscs_job_details ( job_id as i64 , None , None ) . await {
377396 Ok ( Some ( details) ) => Ok ( Some ( Event :: User ( UserEvent :: Cscs ( CscsEvent :: GotJobDetails ( details) ) ) ) ) ,
378397 Ok ( None ) => Ok ( Some ( Event :: None ) ) ,
0 commit comments