@@ -263,13 +263,17 @@ class NCLifecycle {
263
263
} ) ;
264
264
265
265
if ( candidates . delete_candidates ?. length > 0 ) {
266
+ const expiration = lifecycle_rule . expiration ? this . _get_expiration_time ( lifecycle_rule . expiration ) : 0 ;
267
+ const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
268
+
266
269
const delete_res = await this . _call_op_and_update_status ( {
267
270
bucket_name,
268
271
rule_id,
269
272
op_name : TIMED_OPS . DELETE_MULTIPLE_OBJECTS ,
270
273
op_func : async ( ) => object_sdk . delete_multiple_objects ( {
271
274
bucket : bucket_json . name ,
272
- objects : candidates . delete_candidates
275
+ objects : candidates . delete_candidates ,
276
+ filter_func
273
277
} )
274
278
} ) ;
275
279
if ( should_notify ) {
@@ -413,18 +417,6 @@ class NCLifecycle {
413
417
//////// EXPIRATION HELPERS ////////
414
418
////////////////////////////////////
415
419
416
- /**
417
- * @param {Object } entry list object entry
418
- */
419
- _get_lifecycle_object_info_from_list_object_entry ( entry ) {
420
- return {
421
- key : entry . key ,
422
- age : this . _get_file_age_days ( entry . create_time ) ,
423
- size : entry . size ,
424
- tags : entry . tagging ,
425
- } ;
426
- }
427
-
428
420
/**
429
421
* get_candidates_by_expiration_rule processes the expiration rule
430
422
* @param {* } lifecycle_rule
@@ -484,8 +476,8 @@ class NCLifecycle {
484
476
// also should maybe create a helper function or add argument for a filter in list object
485
477
const objects_list = await this . load_objects_list ( object_sdk , lifecycle_rule , bucket_json , rule_state ) ;
486
478
objects_list . objects . forEach ( obj => {
487
- const lifecycle_object = this . _get_lifecycle_object_info_from_list_object_entry ( obj ) ;
488
- if ( filter_func ( lifecycle_object ) ) {
479
+ const should_delete = lifecycle_utils . file_matches_filter ( { obj_info : obj , filter_func } ) ;
480
+ if ( should_delete ) {
489
481
//need to delete latest. so remove version_id if exists
490
482
const candidate = _ . omit ( obj , [ 'version_id' ] ) ;
491
483
filtered_objects . push ( candidate ) ;
@@ -516,7 +508,7 @@ class NCLifecycle {
516
508
* @returns
517
509
*/
518
510
filter_expired_delete_marker ( object , next_object , filter_func ) {
519
- const lifecycle_info = this . _get_lifecycle_object_info_from_list_object_entry ( object ) ;
511
+ const lifecycle_info = lifecycle_utils . get_lifecycle_object_info_for_filter ( object ) ;
520
512
if ( ! filter_func ( lifecycle_info ) ) return false ;
521
513
return object . is_latest && object . delete_marker && object . key !== next_object . key ;
522
514
}
@@ -542,7 +534,7 @@ class NCLifecycle {
542
534
}
543
535
}
544
536
const last_item = versions_list . objects . length > 0 && versions_list . objects [ versions_list . objects . length - 1 ] ;
545
- const lifecycle_info = this . _get_lifecycle_object_info_from_list_object_entry ( last_item ) ;
537
+ const lifecycle_info = lifecycle_utils . get_lifecycle_object_info_for_filter ( last_item ) ;
546
538
if ( last_item . is_latest && last_item . delete_marker && filter_func ( lifecycle_info ) ) {
547
539
if ( rule_state . is_finished ) {
548
540
candidates . push ( last_item ) ;
@@ -640,7 +632,7 @@ class NCLifecycle {
640
632
const delete_candidates = [ ] ;
641
633
642
634
for ( const entry of versions_list . objects ) {
643
- const lifecycle_info = this . _get_lifecycle_object_info_from_list_object_entry ( entry ) ;
635
+ const lifecycle_info = lifecycle_utils . get_lifecycle_object_info_for_filter ( entry ) ;
644
636
if ( ( num_newer_versions === undefined || this . filter_newer_versions ( entry , rule_state , num_newer_versions ) ) &&
645
637
( num_non_current_days === undefined || this . filter_noncurrent_days ( entry , num_non_current_days ) ) ) {
646
638
if ( filter_func ( lifecycle_info ) ) {
@@ -706,7 +698,7 @@ class NCLifecycle {
706
698
_get_lifecycle_object_info_for_mpu ( create_params_parsed , stat ) {
707
699
return {
708
700
key : create_params_parsed . key ,
709
- age : this . _get_file_age_days ( stat . mtime . getTime ( ) ) ,
701
+ age : lifecycle_utils . get_file_age_days ( stat . mtime . getTime ( ) ) ,
710
702
tags : create_params_parsed . tagging ,
711
703
} ;
712
704
}
@@ -738,15 +730,6 @@ class NCLifecycle {
738
730
} ;
739
731
}
740
732
741
- /**
742
- * get file time since last modified in days
743
- * @param {Number } mtime
744
- * @returns {Number } days since object was last modified
745
- */
746
- _get_file_age_days ( mtime ) {
747
- return Math . floor ( ( Date . now ( ) - mtime ) / 24 / 60 / 60 / 1000 ) ;
748
- }
749
-
750
733
/**
751
734
* get the expiration time in days of an object
752
735
* if rule is set with date, then rule is applied for all objects after that date
0 commit comments