@@ -74,7 +74,7 @@ impl FileArchiver {
74
74
if temporary_archive_path. exists ( ) {
75
75
if let Err ( remove_error) = fs:: remove_file ( & temporary_archive_path) {
76
76
warn ! (
77
- self . logger, " > Post snapshotter.snapshot failure, could not remove temporary archive" ;
77
+ self . logger, " > Post FileArchiver.archive failure, could not remove temporary archive" ;
78
78
"archive_path" => temporary_archive_path. display( ) ,
79
79
"error" => remove_error
80
80
) ;
@@ -206,30 +206,28 @@ impl FileArchiver {
206
206
archive. filepath. display( )
207
207
) ;
208
208
209
- let mut snapshot_file_tar = File :: open ( & archive. filepath ) . with_context ( || {
209
+ let mut archive_file_tar = File :: open ( & archive. filepath ) . with_context ( || {
210
210
format ! (
211
211
"Verify archive error: can not open archive: '{}'" ,
212
212
archive. filepath. display( )
213
213
)
214
214
} ) ?;
215
- snapshot_file_tar . seek ( SeekFrom :: Start ( 0 ) ) ?;
215
+ archive_file_tar . seek ( SeekFrom :: Start ( 0 ) ) ?;
216
216
217
- let mut snapshot_archive : Archive < Box < dyn Read > > = match archive. compression_algorithm {
217
+ let mut tar_archive : Archive < Box < dyn Read > > = match archive. compression_algorithm {
218
218
CompressionAlgorithm :: Gzip => {
219
- let snapshot_file_tar = GzDecoder :: new ( snapshot_file_tar ) ;
220
- Archive :: new ( Box :: new ( snapshot_file_tar ) )
219
+ let archive_decoder = GzDecoder :: new ( archive_file_tar ) ;
220
+ Archive :: new ( Box :: new ( archive_decoder ) )
221
221
}
222
222
CompressionAlgorithm :: Zstandard => {
223
- let snapshot_file_tar = Decoder :: new ( snapshot_file_tar ) ?;
224
- Archive :: new ( Box :: new ( snapshot_file_tar ) )
223
+ let archive_decoder = Decoder :: new ( archive_file_tar ) ?;
224
+ Archive :: new ( Box :: new ( archive_decoder ) )
225
225
}
226
226
} ;
227
227
228
228
let unpack_temp_dir = self
229
229
. verification_temp_dir
230
- . join ( "mithril_archiver_verify_archive" )
231
230
// Add the archive name to the directory to allow two verifications at the same time
232
- // (useful for tests).
233
231
. join ( archive. filepath . file_name ( ) . ok_or ( anyhow ! (
234
232
"Verify archive error: Could not append archive name to temp directory: archive `{}`" ,
235
233
archive. filepath. display( ) ,
@@ -246,7 +244,7 @@ impl FileArchiver {
246
244
247
245
let verify_result = {
248
246
let mut result = Ok ( ( ) ) ;
249
- for e in snapshot_archive . entries ( ) ? {
247
+ for e in tar_archive . entries ( ) ? {
250
248
match e {
251
249
Err ( e) => {
252
250
result = Err ( anyhow ! ( e) . context ( "Verify archive error: invalid entry" ) ) ;
@@ -290,13 +288,6 @@ impl FileArchiver {
290
288
291
289
Ok ( ( ) )
292
290
}
293
-
294
- #[ cfg( test) ]
295
- /// Allow to use a custom temporary directory to avoid conflicts during the snapshot verification.
296
- pub fn set_verification_temp_dir < T : Into < String > > ( & mut self , sub_dir : T ) {
297
- self . verification_temp_dir =
298
- mithril_common:: test_utils:: TempDir :: create ( "snapshotter-temp" , sub_dir) ;
299
- }
300
291
}
301
292
302
293
#[ cfg( test) ]
@@ -305,10 +296,8 @@ mod tests {
305
296
306
297
use mithril_common:: test_utils:: assert_equivalent;
307
298
308
- use crate :: test_tools:: TestLogger ;
309
299
use crate :: tools:: file_archiver:: appender:: { AppenderDirAll , AppenderFile } ;
310
300
use crate :: tools:: file_archiver:: test_tools:: * ;
311
- use crate :: ZstandardCompressionParameters ;
312
301
313
302
use super :: * ;
314
303
@@ -344,7 +333,7 @@ mod tests {
344
333
fn should_create_a_valid_archive_with_zstandard_compression ( ) {
345
334
let test_dir =
346
335
get_test_directory ( "should_create_a_valid_archive_with_zstandard_compression" ) ;
347
- let target_archive = test_dir. join ( "archive.tar.gz " ) ;
336
+ let target_archive = test_dir. join ( "archive.tar.zst " ) ;
348
337
let archived_directory = test_dir. join ( create_dir ( & test_dir, "archived_directory" ) ) ;
349
338
create_file ( & archived_directory, "file_to_archive.txt" ) ;
350
339
@@ -437,39 +426,27 @@ mod tests {
437
426
target_directory : test_dir. clone ( ) ,
438
427
compression_algorithm : CompressionAlgorithm :: Gzip ,
439
428
} ;
440
- let first_snapshot = file_archiver
429
+ let first_archive = file_archiver
441
430
. archive (
442
431
archive_params. clone ( ) ,
443
432
AppenderDirAll :: new ( archived_directory. clone ( ) ) ,
444
433
)
445
434
. unwrap ( ) ;
446
- let first_snapshot_size = first_snapshot . get_archive_size ( ) ;
435
+ let first_archive_size = first_archive . get_archive_size ( ) ;
447
436
448
437
create_file ( & archived_directory, "another_file_to_archive.txt" ) ;
449
438
450
- let second_snapshot = file_archiver
439
+ let second_archive = file_archiver
451
440
. archive ( archive_params, AppenderDirAll :: new ( archived_directory) )
452
441
. unwrap ( ) ;
453
- let second_snapshot_size = second_snapshot . get_archive_size ( ) ;
442
+ let second_archive_size = second_archive . get_archive_size ( ) ;
454
443
455
- assert_ne ! ( first_snapshot_size , second_snapshot_size ) ;
444
+ assert_ne ! ( first_archive_size , second_archive_size ) ;
456
445
457
- let unpack_path = second_snapshot . unpack_gzip ( & test_dir) ;
446
+ let unpack_path = second_archive . unpack_gzip ( & test_dir) ;
458
447
assert ! ( unpack_path. join( "another_file_to_archive.txt" ) . exists( ) ) ;
459
448
}
460
449
461
- #[ test]
462
- fn can_set_verification_temp_dir_with_str_or_string ( ) {
463
- let mut file_archiver = FileArchiver :: new (
464
- ZstandardCompressionParameters :: default ( ) ,
465
- PathBuf :: new ( ) ,
466
- TestLogger :: stdout ( ) ,
467
- ) ;
468
-
469
- file_archiver. set_verification_temp_dir ( "sub_dir" ) ;
470
- file_archiver. set_verification_temp_dir ( "sub_dir" . to_string ( ) ) ;
471
- }
472
-
473
450
#[ test]
474
451
fn compute_size_of_uncompressed_data_and_archive ( ) {
475
452
let test_dir = get_test_directory ( "compute_size_of_uncompressed_data_and_archive" ) ;
@@ -485,15 +462,15 @@ mod tests {
485
462
target_directory : test_dir. clone ( ) ,
486
463
compression_algorithm : CompressionAlgorithm :: Gzip ,
487
464
} ;
488
- let snapshot = file_archiver
465
+ let archive = file_archiver
489
466
. archive (
490
467
archive_params. clone ( ) ,
491
468
AppenderFile :: append_at_archive_root ( file_path. clone ( ) ) . unwrap ( ) ,
492
469
)
493
470
. unwrap ( ) ;
494
471
495
- let expected_archive_size = file_size:: compute_size_of_path ( & snapshot . filepath ) . unwrap ( ) ;
496
- assert_eq ! ( expected_archive_size, snapshot . get_archive_size( ) , ) ;
497
- assert_eq ! ( 777 , snapshot . get_uncompressed_size( ) ) ;
472
+ let expected_archive_size = file_size:: compute_size_of_path ( & archive . filepath ) . unwrap ( ) ;
473
+ assert_eq ! ( expected_archive_size, archive . get_archive_size( ) , ) ;
474
+ assert_eq ! ( 777 , archive . get_uncompressed_size( ) ) ;
498
475
}
499
476
}
0 commit comments