take into account the walk function when checking if a crawl is already running for a path

This commit is contained in:
Cyberes 2024-01-23 12:23:24 -07:00
parent 11edbeadc3
commit 4a74b00d46
3 changed files with 8 additions and 6 deletions

View File

@ -91,7 +91,7 @@ func PathOutsideRoot(fullPath string) bool {
}
func RetardCheck(fullPath string) {
// Make sure we never do anything outside of the root dir.
// Make sure we never do anything outside the root dir.
if PathOutsideRoot(fullPath) {
panic(fmt.Sprintf("NewItem was not passed an absolute path. The path must start with the RootDir (%s). Failing path: %s", config.GetConfig().RootDir, fullPath))
}

View File

@ -90,7 +90,7 @@ func isSubpath(path, subpath string) bool {
}
func (dc *DirectoryCrawler) startCrawl(path string, function string) bool {
if dc.IsCrawlActive(path) {
if dc.IsCrawlActive(path, &function) {
return false
}
activeCrawls[path] = &ActiveCrawl{
@ -119,11 +119,13 @@ func (dc *DirectoryCrawler) endCrawl(path string) {
delete(activeCrawls, path)
}
func (dc *DirectoryCrawler) IsCrawlActive(path string) bool {
func (dc *DirectoryCrawler) IsCrawlActive(path string, function *string) bool {
activeCrawlsMutex.Lock()
defer activeCrawlsMutex.Unlock()
_, active := activeCrawls[path]
return active
if crawl, active := activeCrawls[path]; active {
return crawl.Function == *function
}
return false
}
func GetActiveCrawls() map[string]*ActiveCrawl {

View File

@ -37,7 +37,7 @@ func CheckAndRecache(path string) {
func Recache(path string) error {
dc := DirectoryCrawler.NewDirectoryCrawler()
if dc.IsCrawlActive(path) {
if dc.IsCrawlActive(path, nil) {
return errors.New("rejecting crawl, already in progress for this path")
}