From a072d6d6e7b62be6eaac5c2898eb79656d329989 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 13 Aug 2018 23:09:49 -0400 Subject: [PATCH] WIP --- check.go | 6 +++--- compare.go | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/check.go b/check.go index 29e05e3..0e63e5a 100644 --- a/check.go +++ b/check.go @@ -5,18 +5,18 @@ package mtree // If keywords is nil, the check all present in the DirectoryHierarchy // // This is equivalent to creating a new DirectoryHierarchy with Walk(root, nil, -// keywords, fs) and then doing a Compare(dh, newDh, keywords). +// keywords, fs) and then doing a Compare(dh, curDh, keywords). func Check(root string, dh *DirectoryHierarchy, keywords []Keyword, fs FsEval) ([]InodeDelta, error) { if keywords == nil { keywords = dh.UsedKeywords() } - newDh, err := Walk(root, nil, keywords, fs) + curDh, err := Walk(root, nil, keywords, fs) if err != nil { return nil, err } - return Compare(dh, newDh, keywords) + return Compare(dh, curDh, keywords) } // TarCheck is the tar equivalent of checking a file hierarchy spec against a diff --git a/compare.go b/compare.go index 5394832..5549e24 100644 --- a/compare.go +++ b/compare.go @@ -325,13 +325,17 @@ 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 +// If thisDh or thatDh are empty, we assume they are a hierarchy that is // completely empty. This is purely for helping callers create synthetic // InodeDeltas. // +// Comparing this directory hierarchy to that directory hierarchy is that +// sometimes it has few than all files, or may not have directories, etc., +// so lack of presence of entries in thisDh may not be reportable. +// // 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) { +func Compare(thisDh, thatDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, error) { // Represents the new and old states for an entry. type stateT struct { Old *Entry @@ -343,8 +347,8 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er diffs := map[string]*stateT{} // First, iterate over the old hierarchy. If nil, pretend it's empty. - if oldDh != nil { - for _, e := range oldDh.Entries { + if thisDh != nil { + for _, e := range thisDh.Entries { if e.Type == RelativeType || e.Type == FullType { path, err := e.Path() if err != nil { @@ -365,8 +369,8 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, er } // Then, iterate over the new hierarchy. If nil, pretend it's empty. - if newDh != nil { - for _, e := range newDh.Entries { + if thatDh != nil { + for _, e := range thatDh.Entries { if e.Type == RelativeType || e.Type == FullType { path, err := e.Path() if err != nil {