1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-06-30 21:28:28 +00:00

*: make Keyword and KeyVal pervasive

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-11-17 19:47:31 -05:00
parent 5d26726bb1
commit 4eec68be4b
Signed by: vbatts
GPG key ID: 10937E57733F1362
18 changed files with 434 additions and 367 deletions

View file

@ -123,7 +123,7 @@ func (i InodeDelta) String() string {
// returned with InodeDelta.Diff().
type KeyDelta struct {
diff DifferenceType
name string
name Keyword
old string
new string
}
@ -136,7 +136,7 @@ func (k KeyDelta) Type() DifferenceType {
// Name returns the name (the key) of the KeyDeltaVal entry in the
// DirectoryHierarchy.
func (k KeyDelta) Name() string {
func (k KeyDelta) Name() Keyword {
return k.name
}
@ -164,7 +164,7 @@ func (k KeyDelta) New() *string {
func (k KeyDelta) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Type DifferenceType `json:"type"`
Name string `json:"name"`
Name Keyword `json:"name"`
Old string `json:"old"`
New string `json:"new"`
}{
@ -184,7 +184,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
New *KeyVal
}
diffs := map[string]*stateT{}
diffs := map[Keyword]*stateT{}
// Fill the map with the old keys first.
for _, kv := range oldEntry.AllKeys() {
@ -218,7 +218,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
// We need a full list of the keys so we can deal with different keyvalue
// orderings.
var kws []string
var kws []Keyword
for kw := range diffs {
kws = append(kws, kw)
}
@ -226,7 +226,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
// If both tar_time and time were specified in the set of keys, we have to
// mess with the diffs. This is an unfortunate side-effect of tar archives.
// TODO(cyphar): This really should be abstracted inside keywords.go
if inSlice("tar_time", kws) && inSlice("time", kws) {
if InKeywordSlice("tar_time", kws) && InKeywordSlice("time", kws) {
// Delete "time".
timeStateT := diffs["time"]
delete(diffs, "time")
@ -312,7 +312,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
//
// 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 []string) ([]InodeDelta, error) {
func Compare(oldDh, newDh *DirectoryHierarchy, keys []Keyword) ([]InodeDelta, error) {
// Represents the new and old states for an entry.
type stateT struct {
Old *Entry
@ -320,7 +320,7 @@ func Compare(oldDh, newDh *DirectoryHierarchy, keys []string) ([]InodeDelta, err
}
// Make dealing with the keys mapping easier.
keySet := map[string]struct{}{}
keySet := map[Keyword]struct{}{}
for _, key := range keys {
keySet[key] = struct{}{}
}