From 0674ce80850bbc08e728fc7a0b23a446fac764b2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 26 May 2015 19:06:54 -0700 Subject: [PATCH] Command diff now properly supports recursive diff --- cmd-diff.go | 7 ++++++- diff.go | 22 ++++++++++++++++++++++ pkg/client/fs/fs_test.go | 5 +++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cmd-diff.go b/cmd-diff.go index bc4b49a8..440b4cf4 100644 --- a/cmd-diff.go +++ b/cmd-diff.go @@ -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 { diff --git a/diff.go b/diff.go index eea853bb..2d34e7ae 100644 --- a/diff.go +++ b/diff.go @@ -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{ diff --git a/pkg/client/fs/fs_test.go b/pkg/client/fs/fs_test.go index ff7af794..1a34895a 100644 --- a/pkg/client/fs/fs_test.go +++ b/pkg/client/fs/fs_test.go @@ -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) {