From 0d03b7838f738da5506c0a394c4239bf65c5dfd5 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 26 May 2015 18:03:06 -0700 Subject: [PATCH 1/3] Update to new changes in minio-go related to userAgent --- Godeps/Godeps.json | 2 +- .../src/github.com/minio/minio-go/low_level_request.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a63d392a..26584a66 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -32,7 +32,7 @@ }, { "ImportPath": "github.com/minio/minio-go", - "Rev": "c68bb5b2c7a043c0769c5ef902e1a1c1572d52a3" + "Rev": "388953f651449b2f1dd6d5b489ff2e6afbe7b901" }, { "ImportPath": "github.com/minio/minio/pkg/iodine", diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/low_level_request.go b/Godeps/_workspace/src/github.com/minio/minio-go/low_level_request.go index 3f3f711c..7047f712 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/low_level_request.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/low_level_request.go @@ -72,8 +72,8 @@ func newRequest(op *operation, config *Config, body io.ReadSeeker) (*request, er return nil, err } - // if userAgent empty do not set it - if config.userAgent != "" { + // if userAgent empty set it + if config.userAgent == "" { config.userAgent = LibraryName + "/" + LibraryVersion + " (" + runtime.GOOS + ", " + runtime.GOARCH + ") " } From a65f43100497c3e08ddc3e1fb3e731e0dec4f16c Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 26 May 2015 19:06:29 -0700 Subject: [PATCH 2/3] Handle symlinks by making them behave like hardlinks --- pkg/client/fs/fs.go | 34 ++++++++++++++++++++++++++++------ pkg/console/console.go | 4 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index ab2e8587..1bf72fdc 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -170,7 +170,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { } defer dir.Close() - fi, err := os.Lstat(f.path) + fi, err := os.Stat(fpath) if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, @@ -195,11 +195,23 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { return } for _, file := range files { + var fi os.FileInfo + fi = file + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { + fi, err = os.Stat(filepath.Join(dir.Name(), file.Name())) + if err != nil { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: iodine.New(err, nil), + } + return + } + } content := &client.Content{ - Name: file.Name(), - Time: file.ModTime(), - Size: file.Size(), - Type: file.Mode(), + Name: fi.Name(), + Time: fi.ModTime(), + Size: fi.Size(), + Type: fi.Mode(), } contentCh <- client.ContentOnChannel{ Content: content, @@ -208,7 +220,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { } default: content := &client.Content{ - Name: dir.Name(), + Name: f.path, Time: fi.ModTime(), Size: fi.Size(), Type: fi.Mode(), @@ -223,6 +235,10 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel) { defer close(contentCh) visitFS := func(fp string, fi os.FileInfo, err error) error { + // fp also sends back itself with visitFS, ignore it we don't need it + if fp == f.path { + return nil + } if err != nil { if strings.Contains(err.Error(), "operation not permitted") || // os.IsNotExist(err) || @@ -231,6 +247,12 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel } return iodine.New(err, nil) // abort } + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { + fi, err = os.Stat(fp) + if err != nil { + return iodine.New(err, nil) + } + } content := &client.Content{ Name: fp, Time: fi.ModTime(), diff --git a/pkg/console/console.go b/pkg/console/console.go index bc4d5828..8dbda0e0 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -182,7 +182,7 @@ var ( if NoJSONPrint { println(themesDB[currThemeName].Error, data[i]) if !NoDebugPrint { - print(themesDB[currThemeName].Error, err) + println(themesDB[currThemeName].Error, err) } return } @@ -236,7 +236,7 @@ var ( if NoJSONPrint { println(themesDB[currThemeName].Error, data[i]) if !NoDebugPrint { - print(themesDB[currThemeName].Error, err) + println(themesDB[currThemeName].Error, err) } return } From 0674ce80850bbc08e728fc7a0b23a446fac764b2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 26 May 2015 19:06:54 -0700 Subject: [PATCH 3/3] 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) {