Merge pull request #1037 from harshavardhana/diff-type-size

diff should handle type and size as well in recursive diff
This commit is contained in:
Harshavardhana
2015-08-24 00:08:37 -07:00
5 changed files with 59 additions and 9 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ func (a AliasMessage) String() string {
return message
}
jsonMessageBytes, e := json.Marshal(a)
fatalIf(probe.NewError(e), "Unable to marshall into JSON.")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(jsonMessageBytes)
}
+55 -5
View File
@@ -19,6 +19,7 @@ package main
import (
"encoding/json"
"errors"
"os"
"path/filepath"
"strings"
"sync"
@@ -281,6 +282,11 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan diff) {
secondTrie := patricia.NewTrie()
wg := new(sync.WaitGroup)
type urlAttr struct {
Size int64
Type os.FileMode
}
wg.Add(1)
go func(ch chan<- diff) {
defer wg.Done()
@@ -292,7 +298,7 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan diff) {
}
return
}
firstTrie.Insert(patricia.Prefix(firstContentCh.Content.Name), struct{}{})
firstTrie.Insert(patricia.Prefix(firstContentCh.Content.Name), urlAttr{firstContentCh.Content.Size, firstContentCh.Content.Type})
}
}(ch)
wg.Add(1)
@@ -306,7 +312,7 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan diff) {
}
return
}
secondTrie.Insert(patricia.Prefix(secondContentCh.Content.Name), struct{}{})
secondTrie.Insert(patricia.Prefix(secondContentCh.Content.Name), urlAttr{secondContentCh.Content.Size, secondContentCh.Content.Type})
}
}(ch)
@@ -341,17 +347,61 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan diff) {
defer close(matchNameCh)
}(matchNameCh)
for matchName := range matchNameCh {
firstURLDelimited := firstClnt.URL().String()[:strings.LastIndex(firstClnt.URL().String(), string(firstClnt.URL().Separator))+1]
secondURLDelimited := secondClnt.URL().String()[:strings.LastIndex(secondClnt.URL().String(), string(secondClnt.URL().Separator))+1]
firstURL := firstURLDelimited + matchName
secondURL := secondURLDelimited + matchName
if !secondTrie.Match(patricia.Prefix(matchName)) {
firstURLDelimited := firstClnt.URL().String()[:strings.LastIndex(firstClnt.URL().String(), string(firstClnt.URL().Separator))+1]
firstURL := firstURLDelimited + matchName
ch <- diff{
message: DiffMessage{
FirstURL: firstURL,
SecondURL: firstClnt.URL().String(),
SecondURL: secondURL,
Diff: "only-in-first",
}.String(),
err: nil,
}
} else {
firstURLAttr := firstTrie.Get(patricia.Prefix(matchName)).(urlAttr)
secondURLAttr := secondTrie.Get(patricia.Prefix(matchName)).(urlAttr)
if firstURLAttr.Type.IsRegular() {
if !secondURLAttr.Type.IsRegular() {
ch <- diff{
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "type",
}.String(),
err: nil,
}
continue
}
}
if firstURLAttr.Type.IsDir() {
if !secondURLAttr.Type.IsDir() {
ch <- diff{
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "type",
}.String(),
err: nil,
}
continue
}
}
if firstURLAttr.Size != secondURLAttr.Size {
ch <- diff{
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "size",
}.String(),
err: nil,
}
}
}
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ func (c ContentMessage) String() string {
return message
}
jsonMessageBytes, e := json.Marshal(c)
fatalIf(probe.NewError(e), "Unable to marshall into JSON.")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(jsonMessageBytes)
}
+1 -1
View File
@@ -58,7 +58,7 @@ func (s MirrorMessage) String() string {
return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Targets)
}
mirrorMessageBytes, e := json.Marshal(s)
fatalIf(probe.NewError(e), "Unable to marshall into JSON.")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(mirrorMessageBytes)
}
+1 -1
View File
@@ -87,7 +87,7 @@ func (s sessionV2) String() string {
CommandArgs: s.Header.CommandArgs,
}
sessionJSONBytes, e := json.Marshal(sessionMesage)
fatalIf(probe.NewError(e), "Unable to marshall into JSON.")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(sessionJSONBytes)
}