From ffb4a05860a280c02d2b336572c42d67f732fd16 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 16 May 2018 20:06:28 +1000 Subject: [PATCH 1/2] travis: update Go version Signed-off-by: Aleksa Sarai --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cb00680..68187b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: go go: - 1.x + - 1.10.x + - 1.9.x - 1.8.x - - 1.7.x - - 1.6.3 sudo: false From be3abf053afc4f73cafadf1bc09305d5a5ad8f9a Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 16 May 2018 19:53:28 +1000 Subject: [PATCH 2/2] compare: allow nil newDh and oldDh This allows people to create synthetic InodeDeltas, which is something that umoci would like to be able to do in order to nicely create 'umoci insert' layers. Signed-off-by: Aleksa Sarai --- compare.go | 64 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/compare.go b/compare.go index 7f55142..5394832 100644 --- a/compare.go +++ b/compare.go @@ -325,6 +325,10 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) { // missing entries and the like). A missing or extra key is treated as a // Modified type. // +// If oldDh or newDh are empty, we assume they are a hierarchy that is +// completely empty. This is purely for helping callers create synthetic +// InodeDeltas. +// // NB: The order of the parameters matters (old, new) because Extra and // Missing are considered as different discrepancy types. func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, error) { @@ -338,43 +342,47 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er // map to make sure we don't start comparing unrelated entries. diffs := map[string]*stateT{} - // First, iterate over the old hierarchy. - for _, e := range oldDh.Entries { - if e.Type == RelativeType || e.Type == FullType { - path, err := e.Path() - if err != nil { - return nil, err - } + // First, iterate over the old hierarchy. If nil, pretend it's empty. + if oldDh != nil { + for _, e := range oldDh.Entries { + if e.Type == RelativeType || e.Type == FullType { + path, err := e.Path() + if err != nil { + return nil, err + } - // Cannot take &kv because it's the iterator. - copy := new(Entry) - *copy = e + // Cannot take &kv because it's the iterator. + copy := new(Entry) + *copy = e - _, ok := diffs[path] - if !ok { - diffs[path] = &stateT{} + _, ok := diffs[path] + if !ok { + diffs[path] = &stateT{} + } + diffs[path].Old = copy } - diffs[path].Old = copy } } - // Then, iterate over the new hierarchy. - for _, e := range newDh.Entries { - if e.Type == RelativeType || e.Type == FullType { - path, err := e.Path() - if err != nil { - return nil, err - } + // Then, iterate over the new hierarchy. If nil, pretend it's empty. + if newDh != nil { + for _, e := range newDh.Entries { + if e.Type == RelativeType || e.Type == FullType { + path, err := e.Path() + if err != nil { + return nil, err + } - // Cannot take &kv because it's the iterator. - copy := new(Entry) - *copy = e + // Cannot take &kv because it's the iterator. + copy := new(Entry) + *copy = e - _, ok := diffs[path] - if !ok { - diffs[path] = &stateT{} + _, ok := diffs[path] + if !ok { + diffs[path] = &stateT{} + } + diffs[path].New = copy } - diffs[path].New = copy } }