@@ -7,26 +7,26 @@ use tokio::{fs, io};
7
7
#[ error( no_from) ]
8
8
pub enum Error {
9
9
#[ error( display = "Failed to get path" ) ]
10
- PathError ( #[ error( source) ] mullvad_paths:: Error ) ,
10
+ Path ( #[ error( source) ] mullvad_paths:: Error ) ,
11
11
12
12
#[ error( display = "Failed to remove directory {}" , _0) ]
13
- RemoveDirError ( String , #[ error( source) ] io:: Error ) ,
13
+ RemoveDir ( String , #[ error( source) ] io:: Error ) ,
14
14
15
15
#[ cfg( not( target_os = "windows" ) ) ]
16
16
#[ error( display = "Failed to create directory {}" , _0) ]
17
- CreateDirError ( String , #[ error( source) ] io:: Error ) ,
17
+ CreateDir ( String , #[ error( source) ] io:: Error ) ,
18
18
19
19
#[ cfg( target_os = "windows" ) ]
20
20
#[ error( display = "Failed to get file type info" ) ]
21
- FileTypeError ( #[ error( source) ] io:: Error ) ,
21
+ FileType ( #[ error( source) ] io:: Error ) ,
22
22
23
23
#[ cfg( target_os = "windows" ) ]
24
24
#[ error( display = "Failed to get dir entry" ) ]
25
- FileEntryError ( #[ error( source) ] io:: Error ) ,
25
+ FileEntry ( #[ error( source) ] io:: Error ) ,
26
26
27
27
#[ cfg( target_os = "windows" ) ]
28
28
#[ error( display = "Failed to read dir entries" ) ]
29
- ReadDirError ( #[ error( source) ] io:: Error ) ,
29
+ ReadDir ( #[ error( source) ] io:: Error ) ,
30
30
}
31
31
32
32
pub async fn clear_directories ( ) -> Result < ( ) , Error > {
@@ -35,12 +35,12 @@ pub async fn clear_directories() -> Result<(), Error> {
35
35
}
36
36
37
37
async fn clear_log_directory ( ) -> Result < ( ) , Error > {
38
- let log_dir = mullvad_paths:: get_log_dir ( ) . map_err ( Error :: PathError ) ?;
38
+ let log_dir = mullvad_paths:: get_log_dir ( ) . map_err ( Error :: Path ) ?;
39
39
clear_directory ( & log_dir) . await
40
40
}
41
41
42
42
async fn clear_cache_directory ( ) -> Result < ( ) , Error > {
43
- let cache_dir = mullvad_paths:: cache_dir ( ) . map_err ( Error :: PathError ) ?;
43
+ let cache_dir = mullvad_paths:: cache_dir ( ) . map_err ( Error :: Path ) ?;
44
44
clear_directory ( & cache_dir) . await
45
45
}
46
46
@@ -49,22 +49,22 @@ async fn clear_directory(path: &Path) -> Result<(), Error> {
49
49
{
50
50
fs:: remove_dir_all ( path)
51
51
. await
52
- . map_err ( |e| Error :: RemoveDirError ( path. display ( ) . to_string ( ) , e) ) ?;
52
+ . map_err ( |e| Error :: RemoveDir ( path. display ( ) . to_string ( ) , e) ) ?;
53
53
fs:: create_dir_all ( path)
54
54
. await
55
- . map_err ( |e| Error :: CreateDirError ( path. display ( ) . to_string ( ) , e) )
55
+ . map_err ( |e| Error :: CreateDir ( path. display ( ) . to_string ( ) , e) )
56
56
}
57
57
#[ cfg( target_os = "windows" ) ]
58
58
{
59
- let mut dir = fs:: read_dir ( & path) . await . map_err ( Error :: ReadDirError ) ?;
59
+ let mut dir = fs:: read_dir ( & path) . await . map_err ( Error :: ReadDir ) ?;
60
60
61
61
let mut result = Ok ( ( ) ) ;
62
62
63
- while let Some ( entry) = dir. next_entry ( ) . await . map_err ( Error :: FileEntryError ) ? {
63
+ while let Some ( entry) = dir. next_entry ( ) . await . map_err ( Error :: FileEntry ) ? {
64
64
let entry_type = match entry. file_type ( ) . await {
65
65
Ok ( entry_type) => entry_type,
66
66
Err ( error) => {
67
- result = result. and ( Err ( Error :: FileTypeError ( error) ) ) ;
67
+ result = result. and ( Err ( Error :: FileType ( error) ) ) ;
68
68
continue ;
69
69
}
70
70
} ;
@@ -74,9 +74,8 @@ async fn clear_directory(path: &Path) -> Result<(), Error> {
74
74
} else {
75
75
fs:: remove_dir_all ( entry. path ( ) ) . await
76
76
} ;
77
- result = result. and (
78
- removal. map_err ( |e| Error :: RemoveDirError ( entry. path ( ) . display ( ) . to_string ( ) , e) ) ,
79
- ) ;
77
+ result = result
78
+ . and ( removal. map_err ( |e| Error :: RemoveDir ( entry. path ( ) . display ( ) . to_string ( ) , e) ) ) ;
80
79
}
81
80
result
82
81
}
0 commit comments