Command diff now properly supports recursive diff

This commit is contained in:
Harshavardhana
2015-05-26 19:21:58 -07:00
parent a65f431004
commit 0674ce8085
3 changed files with 31 additions and 3 deletions
+6 -1
View File
@@ -94,7 +94,12 @@ func runDiffCmd(ctx *cli.Context) {
})
}
}
// TODO recursive is not working yet
if isURLRecursive(secondURL) {
console.Fatals(ErrorMessage{
Message: "Second URL cannot be recursive, diff command is unidirectional",
Error: errInvalidArgument{},
})
}
newFirstURL := stripRecursiveURL(firstURL)
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
if diff.err != nil {
+22
View File
@@ -18,11 +18,27 @@ package main
import (
"path/filepath"
"strings"
"github.com/minio/mc/pkg/client"
"github.com/minio/minio/pkg/iodine"
)
//
// NOTE: All the parse rules should reduced to 1: Diff(First, Second).
//
// Valid cases
// =======================
// 1: diff(f, f) -> diff(f, f)
// 2: diff(f, d) -> copy(f, d/f) -> 1
// 3: diff(d1..., d2) -> []diff(d1/f, d2/f) -> []1
//
// InValid cases
// =======================
// 1. diff(d1..., d2) -> INVALID
// 2. diff(d1..., d2...) -> INVALID
//
type diff struct {
message string
err error
@@ -98,6 +114,12 @@ func dodiffdirs(firstClnt client.Client, firstURL, secondURL string, recursive b
}
return
}
if recursive {
// this special handling is necessary since we are sending back absolute paths with in ListRecursive()
//
// To be consistent we have to filter them out
contentCh.Content.Name = strings.TrimPrefix(contentCh.Content.Name, strings.TrimSuffix(firstURL, "/")+"/")
}
newFirstURL, err := urlJoinPath(firstURL, contentCh.Content.Name)
if err != nil {
ch <- diff{
+3 -2
View File
@@ -104,20 +104,21 @@ func (s *MySuite) TestList(c *C) {
}
c.Assert(err, IsNil)
c.Assert(len(contents), Equals, 5)
c.Assert(len(contents), Equals, 4)
var regularFiles int
var directories int
for _, content := range contents {
if content.Type.IsRegular() {
regularFiles++
continue
}
if content.Type.IsDir() {
directories++
}
}
c.Assert(regularFiles, Equals, 3)
c.Assert(directories, Equals, 2)
c.Assert(directories, Equals, 1)
}
func (s *MySuite) TestPutBucket(c *C) {