@@ -44,38 +44,38 @@ async fn clear_cache_directory() -> Result<(), Error> {
4444}
4545
4646async fn clear_directory ( path : & Path ) -> Result < ( ) , Error > {
47- #[ cfg( not( target_os = "windows" ) ) ]
48- {
49- fs:: remove_dir_all ( path)
50- . await
51- . map_err ( |e| Error :: RemoveDir ( path. display ( ) . to_string ( ) , e) ) ?;
52- fs:: create_dir_all ( path)
53- . await
54- . map_err ( |e| Error :: CreateDir ( path. display ( ) . to_string ( ) , e) )
55- }
56- #[ cfg( target_os = "windows" ) ]
57- {
58- let mut dir = fs:: read_dir ( & path) . await . map_err ( Error :: ReadDir ) ?;
47+ cfg_select ! {
48+ target_os = "windows" => {
49+ let mut dir = fs:: read_dir( & path) . await . map_err( Error :: ReadDir ) ?;
5950
60- let mut result = Ok ( ( ) ) ;
51+ let mut result = Ok ( ( ) ) ;
6152
62- while let Some ( entry) = dir. next_entry ( ) . await . map_err ( Error :: FileEntry ) ? {
63- let entry_type = match entry. file_type ( ) . await {
64- Ok ( entry_type) => entry_type,
65- Err ( error) => {
66- result = result. and ( Err ( Error :: FileType ( error) ) ) ;
67- continue ;
68- }
69- } ;
53+ while let Some ( entry) = dir. next_entry( ) . await . map_err( Error :: FileEntry ) ? {
54+ let entry_type = match entry. file_type( ) . await {
55+ Ok ( entry_type) => entry_type,
56+ Err ( error) => {
57+ result = result. and( Err ( Error :: FileType ( error) ) ) ;
58+ continue ;
59+ }
60+ } ;
7061
71- let removal = if entry_type. is_file ( ) || entry_type. is_symlink ( ) {
72- fs:: remove_file ( entry. path ( ) ) . await
73- } else {
74- fs:: remove_dir_all ( entry. path ( ) ) . await
75- } ;
76- result = result
77- . and ( removal. map_err ( |e| Error :: RemoveDir ( entry. path ( ) . display ( ) . to_string ( ) , e) ) ) ;
62+ let removal = if entry_type. is_file( ) || entry_type. is_symlink( ) {
63+ fs:: remove_file( entry. path( ) ) . await
64+ } else {
65+ fs:: remove_dir_all( entry. path( ) ) . await
66+ } ;
67+ result = result
68+ . and( removal. map_err( |e| Error :: RemoveDir ( entry. path( ) . display( ) . to_string( ) , e) ) ) ;
69+ }
70+ result
71+ }
72+ _ => {
73+ fs:: remove_dir_all( path)
74+ . await
75+ . map_err( |e| Error :: RemoveDir ( path. display( ) . to_string( ) , e) ) ?;
76+ fs:: create_dir_all( path)
77+ . await
78+ . map_err( |e| Error :: CreateDir ( path. display( ) . to_string( ) , e) )
7879 }
79- result
8080 }
8181}
0 commit comments