use a new thread safe map
This commit is contained in:
@@ -18,7 +18,7 @@ type ConfigInterface interface {
|
||||
GetHost() string
|
||||
GetPort() string
|
||||
GetDirectories() []string
|
||||
MeetsConditions(directory, torrentID, torrentName string, fileNames []string) bool
|
||||
MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool
|
||||
GetOnLibraryUpdate() string
|
||||
GetNetworkBufferSize() int
|
||||
GetMountPoint() string
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user