Skip to content

Commit

Permalink
*: fix comparison of missing keywords
Browse files Browse the repository at this point in the history
Adding another test validated from the FreeBSD workflow.

Just because the keywords requested to be validated are not present in
the manifest, it is not an error.
Also, if the keywords from a new manifest are not present in a prior
manifest, then only compare the common keywords.

Fixes #86

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
vbatts committed Nov 18, 2016
1 parent 20310e2 commit 8f3771f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestCheckKeywords(t *testing.T) {
t.Fatal(err)
}
if len(res) != 1 {
t.Errorf("expected to get 1 delta on changed mtimes, but did not")
t.Fatal("expected to get 1 delta on changed mtimes, but did not")
}
if res[0].Type() != Modified {
t.Errorf("expected to get modified delta on changed mtimes, but did not")
Expand Down
10 changes: 3 additions & 7 deletions cmd/gomtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ func app() error {
if (keyword == "time" && mtree.InKeywordSlice("tar_time", specKeywords)) || (keyword == "tar_time" && mtree.InKeywordSlice("time", specKeywords)) {
continue
}

if !mtree.InKeywordSlice(keyword, specKeywords) {
return fmt.Errorf("cannot verify keywords not in mtree specification: %s\n", keyword)
}
}
}

Expand Down Expand Up @@ -263,9 +259,9 @@ func app() error {
if isTarSpec(specDh) || *flTar != "" {
res = filterMissingKeywords(res)
}
if len(res) > 0 {
return fmt.Errorf("unexpected missing keywords: %d", len(res))
}
//if len(res) > 0 {
//return fmt.Errorf("unexpected missing keywords: %d", len(res))
//}

out := formatFunc(res)
if _, err := os.Stdout.Write([]byte(out)); err != nil {
Expand Down
22 changes: 13 additions & 9 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,16 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
}

diffs := map[Keyword]*stateT{}
oldKeys := oldEntry.AllKeys()
newKeys := newEntry.AllKeys()

// Fill the map with the old keys first.
for _, kv := range oldEntry.AllKeys() {
for _, kv := range oldKeys {
key := kv.Keyword()
// only add this diff if the new keys has this keyword
if key != "tar_time" && key != "time" && HasKeyword(newKeys, key) == emptyKV {
continue
}

// Cannot take &kv because it's the iterator.
copy := new(KeyVal)
Expand All @@ -202,8 +208,12 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
}

// Then fill the new keys.
for _, kv := range newEntry.AllKeys() {
for _, kv := range newKeys {
key := kv.Keyword()
// only add this diff if the old keys has this keyword
if key != "tar_time" && key != "time" && HasKeyword(oldKeys, key) == emptyKV {
continue
}

// Cannot take &kv because it's the iterator.
copy := new(KeyVal)
Expand Down Expand Up @@ -319,12 +329,6 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er
New *Entry
}

// Make dealing with the keys mapping easier.
keySet := map[Keyword]struct{}{}
for _, key := range keys {
keySet[key] = struct{}{}
}

// To deal with different orderings of the entries, use a path-keyed
// map to make sure we don't start comparing unrelated entries.
diffs := map[string]*stateT{}
Expand Down Expand Up @@ -405,7 +409,7 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er
if keys != nil {
var filterChanged []KeyDelta
for _, keyDiff := range changed {
if _, ok := keySet[keyDiff.name]; ok {
if InKeywordSlice(keyDiff.name, keys) {
filterChanged = append(filterChanged, keyDiff)
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/cli/0005.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

name=$(basename $0)
root=$1
gomtree=$(readlink -f ${root}/gomtree)
t=$(mktemp -d /tmp/go-mtree.XXXXXX)

echo "[${name}] Running in ${t}"

pushd ${root}
mkdir -p ${t}/extract
git archive --format=tar HEAD^{tree} . | tar -C ${t}/extract/ -x

${gomtree} -k sha1digest -c -p ${t}/extract/ > ${t}/${name}.mtree
${gomtree} -f ${t}/${name}.mtree -k md5digest -p ${t}/extract/

popd
rm -rf ${t}

0 comments on commit 8f3771f

Please sign in to comment.