Merge pull request #1023 from harshavardhana/diffmsg

Use DiffMessage rather than diffV1
This commit is contained in:
Harshavardhana
2015-08-22 02:57:02 -07:00
3 changed files with 47 additions and 57 deletions
+10 -14
View File
@@ -18,32 +18,28 @@ package main
import "encoding/json"
// DiffJSONMessage json container for diff messages
type DiffJSONMessage struct {
// DiffMessage json container for diff messages
type DiffMessage struct {
FirstURL string `json:"first"`
SecondURL string `json:"second"`
Diff string `json:"diff"`
}
func (s diffV1) String() string {
func (d DiffMessage) String() string {
if !globalJSONFlag {
var message string
if s.diffType == "Only-in" {
message = "‘" + s.firstURL + "’ Only in ‘" + s.secondURL + "’\n"
if d.Diff == "Only-in" {
message = "‘" + d.FirstURL + "’ Only in ‘" + d.SecondURL + "’\n"
}
if s.diffType == "Type" {
message = s.firstURL + " and " + s.secondURL + " differs in type.\n"
if d.Diff == "Type" {
message = d.FirstURL + " and " + d.SecondURL + " differs in type.\n"
}
if s.diffType == "Size" {
message = s.firstURL + " and " + s.secondURL + " differs in size.\n"
if d.Diff == "Size" {
message = d.FirstURL + " and " + d.SecondURL + " differs in size.\n"
}
return message
}
diffMessage := DiffJSONMessage{}
diffMessage.FirstURL = s.firstURL
diffMessage.SecondURL = s.secondURL
diffMessage.Diff = s.diffType
diffJSONBytes, err := json.Marshal(diffMessage)
diffJSONBytes, err := json.Marshal(d)
if err != nil {
panic(err)
}
+36 -42
View File
@@ -43,12 +43,6 @@ import (
// 2. diff(d1..., d2...) -> INVALID
//
type diffV1 struct {
firstURL string
secondURL string
diffType string
}
type diff struct {
message string
err *probe.Error
@@ -100,10 +94,10 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diff) {
doDiffObjects(firstURL, newSecondURL, ch)
case !secondContent.Type.IsRegular():
ch <- diff{
message: diffV1{
firstURL: firstURL,
secondURL: secondURL,
diffType: "Type",
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "Type",
}.String(),
err: nil,
}
@@ -116,10 +110,10 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diff) {
switch {
case !secondContent.Type.IsDir():
ch <- diff{
message: diffV1{
firstURL: firstURL,
secondURL: secondURL,
diffType: "Type",
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "Type",
}.String(),
err: nil,
}
@@ -154,10 +148,10 @@ func doDiffObjects(firstURL, secondURL string, ch chan diff) {
case firstContent.Type.IsRegular():
if !secondContent.Type.IsRegular() {
ch <- diff{
message: diffV1{
firstURL: firstURL,
secondURL: secondURL,
diffType: "Type",
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "Type",
}.String(),
err: nil,
}
@@ -172,10 +166,10 @@ func doDiffObjects(firstURL, secondURL string, ch chan diff) {
if firstContent.Size != secondContent.Size {
ch <- diff{
message: diffV1{
firstURL: firstURL,
secondURL: secondURL,
diffType: "Size",
message: DiffMessage{
FirstURL: firstURL,
SecondURL: secondURL,
Diff: "Size",
}.String(),
err: nil,
}
@@ -212,20 +206,20 @@ func dodiff(firstClnt, secondClnt client.Client, ch chan diff) {
switch {
case errFirst != nil && errSecond == nil:
ch <- diff{
message: diffV1{
firstURL: newSecondURL,
secondURL: secondClnt.URL().String(),
diffType: "Only-in",
message: DiffMessage{
FirstURL: newSecondURL,
SecondURL: secondClnt.URL().String(),
Diff: "Only-in",
}.String(),
err: nil,
}
continue
case errFirst == nil && errSecond != nil:
ch <- diff{
message: diffV1{
firstURL: newFirstURL,
secondURL: firstClnt.URL().String(),
diffType: "Only-in",
message: DiffMessage{
FirstURL: newFirstURL,
SecondURL: firstClnt.URL().String(),
Diff: "Only-in",
}.String(),
err: nil,
}
@@ -235,10 +229,10 @@ func dodiff(firstClnt, secondClnt client.Client, ch chan diff) {
case newFirstContent.Type.IsDir():
if !newSecondContent.Type.IsDir() {
ch <- diff{
message: diffV1{
firstURL: newFirstURL,
secondURL: newSecondURL,
diffType: "Type",
message: DiffMessage{
FirstURL: newFirstURL,
SecondURL: newSecondURL,
Diff: "Type",
}.String(),
err: nil,
}
@@ -247,10 +241,10 @@ func dodiff(firstClnt, secondClnt client.Client, ch chan diff) {
case newFirstContent.Type.IsRegular():
if !newSecondContent.Type.IsRegular() {
ch <- diff{
message: diffV1{
firstURL: newFirstURL,
secondURL: newSecondURL,
diffType: "Type",
message: DiffMessage{
FirstURL: newFirstURL,
SecondURL: newSecondURL,
Diff: "Type",
}.String(),
err: nil,
}
@@ -327,10 +321,10 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan diff) {
firstURLDelimited := firstClnt.URL().String()[:strings.LastIndex(firstClnt.URL().String(), string(firstClnt.URL().Separator))+1]
firstURL := firstURLDelimited + matchName
ch <- diff{
message: diffV1{
firstURL: firstURL,
secondURL: firstClnt.URL().String(),
diffType: "Only-in",
message: DiffMessage{
FirstURL: firstURL,
SecondURL: firstClnt.URL().String(),
Diff: "Only-in",
}.String(),
err: nil,
}
+1 -1
View File
@@ -85,7 +85,7 @@ func (e errSourceNotRecursive) Error() string {
return "Source ‘" + e.URL + "’ is not recursive."
}
type errSourceIsNotDir errTargetIsNotDir
type errSourceIsNotDir errInvalidURL
func (e errSourceIsNotDir) Error() string {
return "Source ‘" + e.URL + "’ is not a folder."