Merge pull request #699 from harshavardhana/pr_out_command_diff_now_properly_supports_recursive_diff

This commit is contained in:
Harshavardhana
2015-05-26 19:23:05 -07:00
7 changed files with 64 additions and 14 deletions
+1 -1
View File
@@ -32,7 +32,7 @@
},
{
"ImportPath": "github.com/minio/minio-go",
"Rev": "c68bb5b2c7a043c0769c5ef902e1a1c1572d52a3"
"Rev": "388953f651449b2f1dd6d5b489ff2e6afbe7b901"
},
{
"ImportPath": "github.com/minio/minio/pkg/iodine",
+2 -2
View File
@@ -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 + ") "
}
+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{
+28 -6
View File
@@ -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(),
+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) {
+2 -2
View File
@@ -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
}