@@ -1057,6 +1057,7 @@ check_intersections() {
1057
1057
local main_list=$1
1058
1058
local special_list=$2
1059
1059
local temp_intersect=" ${TMP_DIR} /intersections.tmp"
1060
+ local temp_main=" ${TMP_DIR} /main_without_duplicates.tmp"
1060
1061
1061
1062
log " Checking intersections between lists..."
1062
1063
@@ -1070,31 +1071,43 @@ check_intersections() {
1070
1071
return 1
1071
1072
fi
1072
1073
1073
- # Create temporary file for intersections
1074
- if ! : > " $temp_intersect " ; then
1075
- log " ERROR: Failed to create temporary file for intersections "
1074
+ # Create temporary files
1075
+ if ! : > " $temp_intersect " || ! : > " $temp_main " ; then
1076
+ log " ERROR: Failed to create temporary files "
1076
1077
return 1
1077
1078
fi
1078
1079
1079
1080
# Find intersections using comm
1080
1081
if ! comm -12 <( sort " $main_list " ) <( sort " $special_list " ) > " $temp_intersect " ; then
1081
1082
log " ERROR: Failed to check intersections"
1082
- rm -f " $temp_intersect "
1083
+ rm -f " $temp_intersect " " $temp_main "
1083
1084
return 1
1084
1085
fi
1085
1086
1086
- # Check if we found any intersections
1087
+ # If intersections found, remove them from main list
1087
1088
if [[ -s " $temp_intersect " ]]; then
1088
- log " WARNING: Found intersections between lists :"
1089
+ log " Found intersecting domains - moving to special list :"
1089
1090
while IFS= read -r domain; do
1090
- log " Duplicate domain: $domain "
1091
+ log " Moving domain to special list : $domain "
1091
1092
done < " $temp_intersect "
1092
- rm -f " $temp_intersect "
1093
- return 1
1093
+
1094
+ # Remove intersecting domains from main list
1095
+ if ! grep -vFf " $temp_intersect " " $main_list " > " $temp_main " ; then
1096
+ log " ERROR: Failed to remove intersecting domains from main list"
1097
+ rm -f " $temp_intersect " " $temp_main "
1098
+ return 1
1099
+ fi
1100
+
1101
+ # Update main list
1102
+ if ! mv " $temp_main " " $main_list " ; then
1103
+ log " ERROR: Failed to update main list"
1104
+ rm -f " $temp_intersect " " $temp_main "
1105
+ return 1
1106
+ fi
1094
1107
fi
1095
1108
1096
- rm -f " $temp_intersect "
1097
- log " No intersections found between lists "
1109
+ rm -f " $temp_intersect " " $temp_main "
1110
+ log " Intersection check completed - duplicates moved to special list "
1098
1111
return 0
1099
1112
}
1100
1113
@@ -1675,9 +1688,9 @@ main() {
1675
1688
fi
1676
1689
fi
1677
1690
1678
- # Check for intersections
1691
+ # Check for intersections and move duplicates to special list
1679
1692
if ! check_intersections " ${TMP_DIR} /main_filtered.txt" " ${TMP_DIR} /special_filtered.txt" ; then
1680
- log " ERROR: Intersections found between lists "
1693
+ log " ERROR: Failed to process list intersections "
1681
1694
restore_backups
1682
1695
release_lock
1683
1696
return 1
0 commit comments