use a new thread safe map

This commit is contained in:
Ben Sarmiento
2023-11-18 12:53:39 +01:00
parent b669f8d673
commit 0e9302f3b5
15 changed files with 577 additions and 535 deletions

View File

@@ -63,21 +63,25 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
return result
}
func (z *ZurgConfigV1) MeetsConditions(directory, torrentID, torrentName string, fileNames []string) bool {
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool {
if _, ok := z.Directories[directory]; !ok {
return false
}
for _, filter := range z.Directories[directory].Filters {
if z.matchFilter(torrentID, torrentName, fileNames, filter) {
if z.matchFilter(torrentName, torrentIDs, fileNames, filter) {
return true
}
}
return false
}
func (z *ZurgConfigV1) matchFilter(fileID, torrentName string, fileNames []string, filter *FilterConditionsV1) bool {
if filter.ID != "" && fileID == filter.ID {
return true
func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []string, filter *FilterConditionsV1) bool {
if filter.ID != "" {
for _, torrentID := range torrentIDs {
if torrentID == filter.ID {
return true
}
}
}
if filter.RegexStr != "" {
regex := compilePattern(filter.RegexStr)
@@ -100,7 +104,7 @@ func (z *ZurgConfigV1) matchFilter(fileID, torrentName string, fileNames []strin
if len(filter.And) > 0 {
andResult := true
for _, andFilter := range filter.And {
andResult = andResult && z.matchFilter(fileID, torrentName, fileNames, andFilter)
andResult = andResult && z.matchFilter(torrentName, torrentIDs, fileNames, andFilter)
if !andResult {
return false
}
@@ -109,7 +113,7 @@ func (z *ZurgConfigV1) matchFilter(fileID, torrentName string, fileNames []strin
}
if len(filter.Or) > 0 {
for _, orFilter := range filter.Or {
if z.matchFilter(fileID, torrentName, fileNames, orFilter) {
if z.matchFilter(torrentName, torrentIDs, fileNames, orFilter) {
return true
}
}