mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 21:15:26 +00:00
using synclockmap
This commit is contained in:
parent
4916cf34f0
commit
b05359bc82
@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -26,6 +25,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v3/pkg/workflows"
|
"github.com/projectdiscovery/nuclei/v3/pkg/workflows"
|
||||||
"github.com/projectdiscovery/retryablehttp-go"
|
"github.com/projectdiscovery/retryablehttp-go"
|
||||||
"github.com/projectdiscovery/utils/errkit"
|
"github.com/projectdiscovery/utils/errkit"
|
||||||
|
mapsutil "github.com/projectdiscovery/utils/maps"
|
||||||
sliceutil "github.com/projectdiscovery/utils/slice"
|
sliceutil "github.com/projectdiscovery/utils/slice"
|
||||||
stringsutil "github.com/projectdiscovery/utils/strings"
|
stringsutil "github.com/projectdiscovery/utils/strings"
|
||||||
syncutil "github.com/projectdiscovery/utils/sync"
|
syncutil "github.com/projectdiscovery/utils/sync"
|
||||||
@ -316,7 +316,7 @@ func (store *Store) LoadTemplatesOnlyMetadata() error {
|
|||||||
}
|
}
|
||||||
templatesCache := parserItem.Cache()
|
templatesCache := parserItem.Cache()
|
||||||
|
|
||||||
loadedTemplateIDs := make(map[string]bool)
|
loadedTemplateIDs := mapsutil.NewSyncLockMap[string, struct{}]()
|
||||||
|
|
||||||
for templatePath := range validPaths {
|
for templatePath := range validPaths {
|
||||||
template, _, _ := templatesCache.Has(templatePath)
|
template, _, _ := templatesCache.Has(templatePath)
|
||||||
@ -342,12 +342,12 @@ func (store *Store) LoadTemplatesOnlyMetadata() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if template != nil {
|
if template != nil {
|
||||||
if loadedTemplateIDs[template.ID] {
|
if loadedTemplateIDs.Has(template.ID) {
|
||||||
store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", template.ID, templatePath)
|
store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", template.ID, templatePath)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedTemplateIDs[template.ID] = true
|
loadedTemplateIDs.Set(template.ID, struct{}{})
|
||||||
template.Path = templatePath
|
template.Path = templatePath
|
||||||
store.templates = append(store.templates, template)
|
store.templates = append(store.templates, template)
|
||||||
}
|
}
|
||||||
@ -501,19 +501,15 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ
|
|||||||
templatePathMap := store.pathFilter.Match(includedTemplates)
|
templatePathMap := store.pathFilter.Match(includedTemplates)
|
||||||
|
|
||||||
loadedTemplates := sliceutil.NewSyncSlice[*templates.Template]()
|
loadedTemplates := sliceutil.NewSyncSlice[*templates.Template]()
|
||||||
loadedTemplateIDs := make(map[string]bool)
|
loadedTemplateIDs := mapsutil.NewSyncLockMap[string, struct{}]()
|
||||||
var loadedTemplateIDsMutex sync.Mutex
|
|
||||||
|
|
||||||
loadTemplate := func(tmpl *templates.Template) {
|
loadTemplate := func(tmpl *templates.Template) {
|
||||||
loadedTemplateIDsMutex.Lock()
|
if loadedTemplateIDs.Has(tmpl.ID) {
|
||||||
if loadedTemplateIDs[tmpl.ID] {
|
|
||||||
loadedTemplateIDsMutex.Unlock()
|
|
||||||
store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", tmpl.ID, tmpl.Path)
|
store.logger.Debug().Msgf("Skipping duplicate template ID '%s' from path '%s'", tmpl.ID, tmpl.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedTemplateIDs[tmpl.ID] = true
|
loadedTemplateIDs.Set(tmpl.ID, struct{}{})
|
||||||
loadedTemplateIDsMutex.Unlock()
|
|
||||||
|
|
||||||
loadedTemplates.Append(tmpl)
|
loadedTemplates.Append(tmpl)
|
||||||
// increment signed/unsigned counters
|
// increment signed/unsigned counters
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user