summaryrefslogtreecommitdiff
path: root/manifests.go
diff options
context:
space:
mode:
authorMaciej Wereski <m.wereski@partner.samsung.com>2017-03-07 11:27:38 +0100
committerMaciej Wereski <m.wereski@partner.samsung.com>2017-08-17 08:53:00 +0200
commitf0e22844a344ddeff1fe1f3d3e13865cc3351f99 (patch)
tree156ec77d21a9b8c8a5b44a5ab3b83e6c88dbaed2 /manifests.go
parent4ca227011c7587021655a542ecfd58525e794bc7 (diff)
downloadsnapsync-f0e22844a344ddeff1fe1f3d3e13865cc3351f99.tar.gz
snapsync-f0e22844a344ddeff1fe1f3d3e13865cc3351f99.tar.bz2
snapsync-f0e22844a344ddeff1fe1f3d3e13865cc3351f99.zip
Add support for ignoring blacklisted repositories
This change allows user to use blacklist file (default provided). Such file is a list of regular expressions that describe git repositories (one per line). Default blacklist file makes snapsync ignore profile repositories. Change-Id: I9c82ae82d7b17a4aeeccb18d1c3379a0a08cb37b Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
Diffstat (limited to 'manifests.go')
-rw-r--r--manifests.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/manifests.go b/manifests.go
index d0ea6b5..d8ec446 100644
--- a/manifests.go
+++ b/manifests.go
@@ -20,7 +20,9 @@ import (
"encoding/xml"
"fmt"
"io/ioutil"
+ "log"
"net/http"
+ "regexp"
"sync"
)
@@ -72,9 +74,9 @@ type RepoXML struct {
Repos []RepoElem `xml:"project"`
}
-// parseReposXMLs takes snapshot XMLs as slice of byte slices (one XML per slice).
+// parseReposXMLs takes snapshot XMLs as slice of byte slices (one XML per slice) and blacklist as slice of regular expressions.
// It returns map of commits in git repositories and error.
-func parseReposXMLs(contents [][]byte) (map[string]string, error) {
+func parseReposXMLs(contents [][]byte, blacklist []*regexp.Regexp) (map[string]string, error) {
var repoxml RepoXML
result := make(map[string]string)
errFmt := "Repository %s contains 2 different commits: %s and %s"
@@ -86,6 +88,19 @@ func parseReposXMLs(contents [][]byte) (map[string]string, error) {
}
for _, v := range repoxml.Repos {
+ if blacklist != nil {
+ ignore := false
+ for _, re := range blacklist {
+ if re.MatchString(v.Path) {
+ log.Printf("Ignoring %s (matched pattern: %s)\n", v.Path, re)
+ ignore = true
+ break
+ }
+ }
+ if ignore {
+ continue
+ }
+ }
rev, ok := result[v.Path]
if ok {
// sanity check
@@ -122,9 +137,9 @@ func getBody(url string) ([]byte, error) {
return body, nil
}
-// getSnapshotInfo takes URL to root folder of snapshot. It downloads and parses
+// getSnapshotInfo takes URL to root folder of snapshot and a blacklist. It downloads and parses
// all snapshot manifest XMLs.
-func getSnapshotInfo(url string) (map[string]string, error) {
+func getSnapshotInfo(url string, blacklist []*regexp.Regexp) (map[string]string, error) {
var wg sync.WaitGroup
// download snapshot manifest XML
xmlURL := url + "/build.xml"
@@ -166,5 +181,5 @@ func getSnapshotInfo(url string) (map[string]string, error) {
}
// parse & return
- return parseReposXMLs(manifests)
+ return parseReposXMLs(manifests, blacklist)
}