attempt to fetch files listed in .gitignore

This commit is contained in:
maia tillie arson crimew 2021-10-20 21:07:53 +02:00
parent 08d74d8c9b
commit 2f526378c5
2 changed files with 38 additions and 0 deletions

View File

@ -54,6 +54,10 @@ func (jt *JobTracker) HasWork() bool {
return hasWork
}
func (jt *JobTracker) QueuedJobs() int32 {
return atomic.LoadInt32(&jt.queuedJobs)
}
func (jt *JobTracker) Wait() {
defer close(jt.Queue)

View File

@ -418,6 +418,40 @@ func FetchGit(baseUrl, baseDir string) error {
} else {
return err
}
ignorePath := utils.Url(baseDir, ".gitignore")
if utils.Exists(ignorePath) {
log.Info().Str("base", baseDir).Msg("atempting to fetch ignored files")
ignoreFile, err := os.Open(ignorePath)
if err != nil {
return err
}
defer ignoreFile.Close()
jt = jobtracker.NewJobTracker()
scanner := bufio.NewScanner(ignoreFile)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
commentStrip := strings.SplitN(line, "#", 1)
line = commentStrip[0]
if line == "" || strings.HasPrefix(line, "!") || strings.HasSuffix(line, "/") || strings.ContainsRune(line, '*') || strings.HasSuffix(line, ".php") {
continue
}
jt.AddJob(line)
}
if err := scanner.Err(); err != nil {
return err
}
concurrency = utils.MinInt(maxConcurrency, int(jt.QueuedJobs()))
for w := 1; w <= concurrency; w++ {
go workers.DownloadWorker(c, baseUrl, baseDir, jt, true, true)
}
jt.Wait()
}
}
return nil
}