@@ -271,7 +271,7 @@ class NCLifecycle {
271
271
272
272
if ( candidates . delete_candidates ?. length > 0 ) {
273
273
const expiration = lifecycle_rule . expiration ? this . _get_expiration_time ( lifecycle_rule . expiration ) : 0 ;
274
- const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
274
+ const filter_func = lifecycle_utils . build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
275
275
dbg . log0 ( 'process_rule: calling delete_multiple_objects, num of objects to be deleted' , candidates . delete_candidates . length ) ;
276
276
const delete_res = await this . _call_op_and_update_status ( {
277
277
bucket_name,
@@ -478,7 +478,7 @@ class NCLifecycle {
478
478
if ( rule_state . is_finished ) return [ ] ;
479
479
const expiration = this . _get_expiration_time ( lifecycle_rule . expiration ) ;
480
480
if ( expiration < 0 ) return [ ] ;
481
- const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
481
+ const filter_func = lifecycle_utils . build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
482
482
483
483
const filtered_objects = [ ] ;
484
484
// TODO list_objects does not accept a filter and works in batch sizes of 1000. should handle batching
@@ -537,7 +537,7 @@ class NCLifecycle {
537
537
const versions_list = params . versions_list ;
538
538
const candidates = [ ] ;
539
539
const expiration = lifecycle_rule . expiration ?. days ? this . _get_expiration_time ( lifecycle_rule . expiration ) : 0 ;
540
- const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
540
+ const filter_func = lifecycle_utils . build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
541
541
for ( let i = 0 ; i < versions_list . objects . length - 1 ; i ++ ) {
542
542
if ( this . filter_expired_delete_marker ( versions_list . objects [ i ] , versions_list . objects [ i + 1 ] , filter_func ) ) {
543
543
candidates . push ( versions_list . objects [ i ] ) ;
@@ -640,7 +640,7 @@ class NCLifecycle {
640
640
}
641
641
const versions_list = params . versions_list ;
642
642
643
- const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration : 0 } ) ;
643
+ const filter_func = lifecycle_utils . build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration : 0 } ) ;
644
644
const num_newer_versions = lifecycle_rule . noncurrent_version_expiration . newer_noncurrent_versions ;
645
645
const num_non_current_days = lifecycle_rule . noncurrent_version_expiration . noncurrent_days ;
646
646
const delete_candidates = [ ] ;
@@ -674,7 +674,7 @@ class NCLifecycle {
674
674
const expiration = lifecycle_rule . abort_incomplete_multipart_upload . days_after_initiation ;
675
675
const res = [ ] ;
676
676
677
- const filter_func = this . _build_lifecycle_filter ( { filter, expiration} ) ;
677
+ const filter_func = lifecycle_utils . build_lifecycle_filter ( { filter, expiration} ) ;
678
678
let dir_handle ;
679
679
//TODO this is almost identical to list_uploads except for error handling and support for pagination. should modify list-upload and use it in here instead
680
680
try {
@@ -720,29 +720,6 @@ class NCLifecycle {
720
720
///////// FILTER HELPERS ////////
721
721
////////////////////////////////////
722
722
723
- /**
724
- * @typedef {{
725
- * filter: Object
726
- * expiration: Number
727
- * }} filter_params
728
- *
729
- * @param {filter_params } params
730
- * @returns
731
- */
732
- _build_lifecycle_filter ( params ) {
733
- /**
734
- * @param {Object } object_info
735
- */
736
- return function ( object_info ) {
737
- if ( params . filter ?. prefix && ! object_info . key . startsWith ( params . filter . prefix ) ) return false ;
738
- if ( params . expiration && object_info . age < params . expiration ) return false ;
739
- if ( params . filter ?. tags && ! _file_contain_tags ( object_info , params . filter . tags ) ) return false ;
740
- if ( params . filter ?. object_size_greater_than && object_info . size < params . filter . object_size_greater_than ) return false ;
741
- if ( params . filter ?. object_size_less_than && object_info . size > params . filter . object_size_less_than ) return false ;
742
- return true ;
743
- } ;
744
- }
745
-
746
723
/**
747
724
* get the expiration time in days of an object
748
725
* if rule is set with date, then rule is applied for all objects after that date
@@ -1468,38 +1445,6 @@ class NCLifecycle {
1468
1445
}
1469
1446
}
1470
1447
1471
- //////////////////
1472
- // TAGS HELPERS //
1473
- //////////////////
1474
-
1475
- /**
1476
- * checks if tag query_tag is in the list tag_set
1477
- * @param {Object } query_tag
1478
- * @param {Array<Object> } tag_set
1479
- */
1480
- function _list_contain_tag ( query_tag , tag_set ) {
1481
- for ( const t of tag_set ) {
1482
- if ( t . key === query_tag . key && t . value === query_tag . value ) return true ;
1483
- }
1484
- return false ;
1485
- }
1486
-
1487
- /**
1488
- * checks if object has all the tags in filter_tags
1489
- * @param {Object } object_info
1490
- * @param {Array<Object> } filter_tags
1491
- * @returns
1492
- */
1493
- function _file_contain_tags ( object_info , filter_tags ) {
1494
- if ( object_info . tags === undefined ) return false ;
1495
- for ( const tag of filter_tags ) {
1496
- if ( ! _list_contain_tag ( tag , object_info . tags ) ) {
1497
- return false ;
1498
- }
1499
- }
1500
- return true ;
1501
- }
1502
-
1503
1448
// EXPORTS
1504
1449
exports . NCLifecycle = NCLifecycle ;
1505
1450
exports . ILM_POLICIES_TMP_DIR = ILM_POLICIES_TMP_DIR ;
0 commit comments