@@ -31,19 +31,29 @@ pub fn is_directory_quasi_empty(path: &Path) -> Result<bool> {
31
31
if path. is_dir ( ) {
32
32
let mut entries = match path. read_dir ( ) {
33
33
Ok ( entries) => entries,
34
- Err ( e) => { bail ! ( "Could not read `{}` because of error: {}" , path. to_string_lossy( ) . to_string( ) , e) ; }
34
+ Err ( e) => {
35
+ bail ! (
36
+ "Could not read `{}` because of error: {}" ,
37
+ path. to_string_lossy( ) . to_string( ) ,
38
+ e
39
+ ) ;
40
+ }
35
41
} ;
36
42
// If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error
37
43
if entries. any ( |x| match x {
38
- Ok ( file) => !file. file_name ( ) . to_str ( ) . expect ( "Could not convert filename to &str" ) . starts_with ( "." ) ,
39
- Err ( _) => true
44
+ Ok ( file) => !file
45
+ . file_name ( )
46
+ . to_str ( )
47
+ . expect ( "Could not convert filename to &str" )
48
+ . starts_with ( '.' ) ,
49
+ Err ( _) => true ,
40
50
} ) {
41
- return Ok ( false )
51
+ return Ok ( false ) ;
42
52
}
43
- return Ok ( true )
44
- } else {
45
- return Ok ( false )
53
+ return Ok ( true ) ;
46
54
}
55
+
56
+ Ok ( false )
47
57
}
48
58
49
59
pub fn create_new_project ( name : & str ) -> Result < ( ) > {
@@ -54,7 +64,10 @@ pub fn create_new_project(name: &str) -> Result<()> {
54
64
if name == "." {
55
65
bail ! ( "The current directory is not an empty folder (hidden files are ignored)." ) ;
56
66
} else {
57
- bail ! ( "`{}` is not an empty folder (hidden files are ignored)." , path. to_string_lossy( ) . to_string( ) )
67
+ bail ! (
68
+ "`{}` is not an empty folder (hidden files are ignored)." ,
69
+ path. to_string_lossy( ) . to_string( )
70
+ )
58
71
}
59
72
}
60
73
} else {
@@ -96,9 +109,9 @@ pub fn create_new_project(name: &str) -> Result<()> {
96
109
97
110
#[ cfg( test) ]
98
111
mod tests {
99
- use std:: env:: temp_dir;
100
- use std:: fs:: { create_dir, remove_dir, remove_dir_all} ;
101
112
use super :: * ;
113
+ use std:: env:: temp_dir;
114
+ use std:: fs:: { create_dir, remove_dir, remove_dir_all} ;
102
115
103
116
#[ test]
104
117
fn init_empty_directory ( ) {
@@ -108,7 +121,8 @@ mod tests {
108
121
remove_dir_all ( & dir) . expect ( "Could not free test directory" ) ;
109
122
}
110
123
create_dir ( & dir) . expect ( "Could not create test directory" ) ;
111
- let allowed = is_directory_quasi_empty ( & dir) . expect ( "An error happened reading the directory's contents" ) ;
124
+ let allowed = is_directory_quasi_empty ( & dir)
125
+ . expect ( "An error happened reading the directory's contents" ) ;
112
126
remove_dir ( & dir) . unwrap ( ) ;
113
127
assert_eq ! ( true , allowed) ;
114
128
}
@@ -124,7 +138,8 @@ mod tests {
124
138
let mut content = dir. clone ( ) ;
125
139
content. push ( "content" ) ;
126
140
create_dir ( & content) . unwrap ( ) ;
127
- let allowed = is_directory_quasi_empty ( & dir) . expect ( "An error happened reading the directory's contents" ) ;
141
+ let allowed = is_directory_quasi_empty ( & dir)
142
+ . expect ( "An error happened reading the directory's contents" ) ;
128
143
remove_dir ( & content) . unwrap ( ) ;
129
144
remove_dir ( & dir) . unwrap ( ) ;
130
145
assert_eq ! ( false , allowed) ;
@@ -141,7 +156,8 @@ mod tests {
141
156
let mut git = dir. clone ( ) ;
142
157
git. push ( ".git" ) ;
143
158
create_dir ( & git) . unwrap ( ) ;
144
- let allowed = is_directory_quasi_empty ( & dir) . expect ( "An error happened reading the directory's contents" ) ;
159
+ let allowed = is_directory_quasi_empty ( & dir)
160
+ . expect ( "An error happened reading the directory's contents" ) ;
145
161
remove_dir ( & git) . unwrap ( ) ;
146
162
remove_dir ( & dir) . unwrap ( ) ;
147
163
assert_eq ! ( true , allowed) ;
0 commit comments