From 2f526378c520dab70cdcf15fa68d2c98bb8eeceb Mon Sep 17 00:00:00 2001 From: maia tillie arson crimew Date: Wed, 20 Oct 2021 21:07:53 +0200 Subject: [PATCH] attempt to fetch files listed in .gitignore --- internal/jobtracker/jobtracker.go | 4 ++++ pkg/goop/clone.go | 34 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/internal/jobtracker/jobtracker.go b/internal/jobtracker/jobtracker.go index 55d2277..0b92588 100644 --- a/internal/jobtracker/jobtracker.go +++ b/internal/jobtracker/jobtracker.go @@ -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) diff --git a/pkg/goop/clone.go b/pkg/goop/clone.go index 2b1467b..05203c8 100644 --- a/pkg/goop/clone.go +++ b/pkg/goop/clone.go @@ -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 }