OwnerUuid: item_map["owner_uuid"].(string),
BlockDigestToSize: make(map[string]int)}
manifest := manifest.Manifest{item_map["manifest_text"].(string)}
- blockChannel := manifest.DuplicateBlockIter()
+ blockChannel := manifest.BlockIterWithDuplicates()
for block := range blockChannel {
if stored_size, stored := collection.BlockDigestToSize[block.Digest];
stored && stored_size != block.Size {
package manifest
import (
+ "bufio"
"fmt"
"log"
"regexp"
m.StreamName = tokens[0]
tokens = tokens[1:]
var i int
- var token string
- for i, token = range tokens {
- if !LocatorPattern.MatchString(token) {
+ for i = range tokens {
+ if !LocatorPattern.MatchString(tokens[i]) {
break
}
}
func (m *Manifest) LineIter() <-chan ManifestLine {
ch := make(chan ManifestLine)
- go func(remaining string) {
- for {
+ go func(input string) {
+ scanner := bufio.NewScanner(strings.NewReader(input))
+ for scanner.Scan() {
// We parse one line at a time, to save effort if we only need
// the first few lines.
- splitsies := strings.SplitN(remaining, "\n", 2)
- ch <- parseManifestLine(splitsies[0])
- if len(splitsies) == 1 {
- break
- }
- remaining = splitsies[1]
+ ch <- parseManifestLine(scanner.Text())
}
close(ch)
}(m.Text)
// Blocks may appear mulitple times within the same manifest if they
// are used by multiple files. In that case this Iterator will output
// the same block multiple times.
-func (m *Manifest) DuplicateBlockIter() <-chan BlockLocator {
+func (m *Manifest) BlockIterWithDuplicates() <-chan BlockLocator {
blockChannel := make(chan BlockLocator)
go func(lineChannel <-chan ManifestLine) {
for m := range lineChannel {
}
}
+func expectLocatorPatternFail(t *testing.T, s string) {
+ if LocatorPattern.MatchString(s) {
+ t.Fatalf("Expected \"%s\" to fail locator pattern but it passed.",
+ s)
+ }
+}
+
func TestLocatorPatternBasic(t *testing.T) {
expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345")
+ expectLocatorPatternMatch(t, "A2345678901234abcdefababdeffdfdf+12345")
+ expectLocatorPatternMatch(t, "12345678901234567890123456789012+12345+A1")
+ expectLocatorPatternMatch(t,
+ "12345678901234567890123456789012+12345+A1+B123wxyz@_-")
+ expectLocatorPatternMatch(t,
+ "12345678901234567890123456789012+12345+A1+B123wxyz@_-+C@")
+
+ expectLocatorPatternFail(t, "12345678901234567890123456789012")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+")
+ expectLocatorPatternFail(t, "1234567890123456789012345678901+12345")
+ expectLocatorPatternFail(t, "123456789012345678901234567890123+12345")
+ expectLocatorPatternFail(t, "g2345678901234abcdefababdeffdfdf+12345")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345 ")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+1A")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+a1")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A1+B")
+ expectLocatorPatternFail(t, "12345678901234567890123456789012+12345+A+B2")
}
func TestParseManifestLineSimple(t *testing.T) {