1
- use std:: ops:: Not ;
2
1
use std:: {
3
2
fs,
3
+ ops:: Not ,
4
4
path:: { Path , PathBuf } ,
5
5
} ;
6
6
@@ -34,7 +34,7 @@ pub enum CardanoDbDownloadCheckerError {
34
34
/// The directory where the files from cardano db are expanded is not empty.
35
35
/// An error is raised to let the user handle what it wants to do with those
36
36
/// files.
37
- #[ error( "Unpack directory '{0}' is not empty, please clean up it's content." ) ]
37
+ #[ error( "Unpack directory '{0}' is not empty, please clean up its content." ) ]
38
38
UnpackDirectoryNotEmpty ( PathBuf ) ,
39
39
40
40
/// Cannot write in the given directory.
@@ -45,7 +45,7 @@ pub enum CardanoDbDownloadCheckerError {
45
45
impl CardanoDbDownloadChecker {
46
46
/// Ensure that the given path exist, create it otherwise
47
47
pub fn ensure_dir_exist ( pathdir : & Path ) -> MithrilResult < ( ) > {
48
- if ! pathdir. exists ( ) {
48
+ if pathdir. exists ( ) . not ( ) {
49
49
fs:: create_dir_all ( pathdir) . map_err ( |e| {
50
50
CardanoDbDownloadCheckerError :: UnpackDirectoryIsNotWritable (
51
51
pathdir. to_owned ( ) ,
@@ -64,12 +64,12 @@ impl CardanoDbDownloadChecker {
64
64
size : u64 ,
65
65
compression_algorithm : CompressionAlgorithm ,
66
66
) -> MithrilResult < ( ) > {
67
- Self :: check_path_is_dir_and_writable ( pathdir) ?;
67
+ Self :: check_path_is_an_empty_dir ( pathdir) ?;
68
68
Self :: check_dir_writable ( pathdir) ?;
69
69
Self :: check_disk_space ( pathdir, size, compression_algorithm)
70
70
}
71
71
72
- fn check_path_is_dir_and_writable ( pathdir : & Path ) -> MithrilResult < ( ) > {
72
+ fn check_path_is_an_empty_dir ( pathdir : & Path ) -> MithrilResult < ( ) > {
73
73
if pathdir. is_dir ( ) . not ( ) {
74
74
anyhow:: bail!( "Given path is not a directory: {}" , pathdir. display( ) ) ;
75
75
}
@@ -158,7 +158,6 @@ mod test {
158
158
create_temporary_empty_directory ( "fail_if_pathdir_is_file" ) . join ( "target_directory" ) ;
159
159
fs:: File :: create ( & pathdir) . unwrap ( ) ;
160
160
161
- CardanoDbDownloadChecker :: ensure_dir_exist ( & pathdir) . unwrap ( ) ;
162
161
CardanoDbDownloadChecker :: check_prerequisites (
163
162
& pathdir,
164
163
12 ,
@@ -167,27 +166,12 @@ mod test {
167
166
. expect_err ( "check_prerequisites should fail" ) ;
168
167
}
169
168
170
- #[ test]
171
- fn return_ok_if_unpack_directory_does_not_exist ( ) {
172
- let pathdir =
173
- create_temporary_empty_directory ( "directory_does_not_exist" ) . join ( "target_directory" ) ;
174
-
175
- CardanoDbDownloadChecker :: ensure_dir_exist ( & pathdir) . unwrap ( ) ;
176
- CardanoDbDownloadChecker :: check_prerequisites (
177
- & pathdir,
178
- 12 ,
179
- CompressionAlgorithm :: default ( ) ,
180
- )
181
- . expect ( "check_prerequisites should not fail" ) ;
182
- }
183
-
184
169
#[ test]
185
170
fn return_ok_if_unpack_directory_exist_and_empty ( ) {
186
171
let pathdir =
187
172
create_temporary_empty_directory ( "existing_directory" ) . join ( "target_directory" ) ;
188
173
fs:: create_dir_all ( & pathdir) . unwrap ( ) ;
189
174
190
- CardanoDbDownloadChecker :: ensure_dir_exist ( & pathdir) . unwrap ( ) ;
191
175
CardanoDbDownloadChecker :: check_prerequisites (
192
176
& pathdir,
193
177
12 ,
@@ -202,7 +186,6 @@ mod test {
202
186
fs:: create_dir_all ( & pathdir) . unwrap ( ) ;
203
187
fs:: File :: create ( pathdir. join ( "file.txt" ) ) . unwrap ( ) ;
204
188
205
- CardanoDbDownloadChecker :: ensure_dir_exist ( & pathdir) . unwrap ( ) ;
206
189
let error = CardanoDbDownloadChecker :: check_prerequisites (
207
190
& pathdir,
208
191
12 ,
@@ -224,9 +207,9 @@ mod test {
224
207
fn return_error_if_not_enough_available_space ( ) {
225
208
let pathdir =
226
209
create_temporary_empty_directory ( "enough_available_space" ) . join ( "target_directory" ) ;
210
+ fs:: create_dir_all ( & pathdir) . unwrap ( ) ;
227
211
let archive_size = u64:: MAX ;
228
212
229
- CardanoDbDownloadChecker :: ensure_dir_exist ( & pathdir) . unwrap ( ) ;
230
213
let error = CardanoDbDownloadChecker :: check_prerequisites (
231
214
& pathdir,
232
215
archive_size,
0 commit comments