1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 00:15:39 +00:00

*: fix comparison of missing keywords

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 https://github.com/vbatts/go-mtree/issues/86

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-11-17 21:29:55 -05:00
parent 4eec68be4b
commit 21723a3974
Signed by: vbatts
GPG key ID: 10937E57733F1362
4 changed files with 36 additions and 17 deletions

View file

@ -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")

View file

@ -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)
}
}
}
@ -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 {

View file

@ -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)
@ -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)
@ -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{}
@ -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)
}
}

19
test/cli/0005.sh Normal file
View file

@ -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}