Merge pull request #752 from harshavardhana/pr_out_more_prefix_url_cleanup
More prefix url cleanup
This commit is contained in:
Generated
+2
-2
@@ -15,7 +15,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/fatih/structs",
|
||||
"Rev": "c06d8730d42f16f3e8dddc236c7d69c0952a8a2c"
|
||||
"Rev": "c00d27128bb88e9c1adab1a53cda9c72c6d1ff9b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/check",
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio-go",
|
||||
"Rev": "745daad6222582eb6ecbb864f0cbcdc4427dd52f"
|
||||
"Rev": "dee5d16f0c4515ddb2785a1b8317ec11796d8fc3"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/minio/pkg/iodine",
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ func Comma(v int64) string {
|
||||
j--
|
||||
}
|
||||
parts[j] = strconv.Itoa(int(v))
|
||||
return sign + strings.Join(parts[j:], ",")
|
||||
return sign + strings.Join(parts[j:len(parts)], ",")
|
||||
}
|
||||
|
||||
// Commaf produces a string form of the given number in base 10 with
|
||||
@@ -97,5 +97,5 @@ func BigComma(b *big.Int) string {
|
||||
j--
|
||||
}
|
||||
parts[j] = strconv.Itoa(int(b.Int64()))
|
||||
return sign + strings.Join(parts[j:], ",")
|
||||
return sign + strings.Join(parts[j:len(parts)], ",")
|
||||
}
|
||||
|
||||
-5
@@ -43,10 +43,6 @@ m := structs.Map(server)
|
||||
// => ["gopher", 123456, true]
|
||||
v := structs.Values(server)
|
||||
|
||||
// Convert the names of a struct to a []string
|
||||
// (see "Names methods" for more info about fields)
|
||||
n := structs.Names(server)
|
||||
|
||||
// Convert the values of a struct to a []*Field
|
||||
// (see "Field methods" for more info about fields)
|
||||
f := structs.Fields(server)
|
||||
@@ -77,7 +73,6 @@ s := structs.New(server)
|
||||
m := s.Map() // Get a map[string]interface{}
|
||||
v := s.Values() // Get a []interface{}
|
||||
f := s.Fields() // Get a []*Field
|
||||
n := s.Names() // Get a []string
|
||||
f := s.Field(name) // Get a *Field based on the given field name
|
||||
f, ok := s.FieldsOk(name) // Get a *Field based on the given field name
|
||||
n := s.Name() // Get the struct name
|
||||
|
||||
-25
@@ -171,25 +171,6 @@ func (s *Struct) Fields() []*Field {
|
||||
return getFields(s.value, s.TagName)
|
||||
}
|
||||
|
||||
// Names returns a slice of field names. A struct tag with the content of "-"
|
||||
// ignores the checking of that particular field. Example:
|
||||
//
|
||||
// // Field is ignored by this package.
|
||||
// Field bool `structs:"-"`
|
||||
//
|
||||
// It panics if s's kind is not struct.
|
||||
func (s *Struct) Names() []string {
|
||||
fields := getFields(s.value, s.TagName)
|
||||
|
||||
names := make([]string, len(fields))
|
||||
|
||||
for i, field := range fields {
|
||||
names[i] = field.Name()
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
func getFields(v reflect.Value, tagName string) []*Field {
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
@@ -406,12 +387,6 @@ func Fields(s interface{}) []*Field {
|
||||
return New(s).Fields()
|
||||
}
|
||||
|
||||
// Names returns a slice of field names. For more info refer to Struct types
|
||||
// Names() method. It panics if s's kind is not struct.
|
||||
func Names(s interface{}) []string {
|
||||
return New(s).Names()
|
||||
}
|
||||
|
||||
// IsZero returns true if all fields is equal to a zero value. For more info
|
||||
// refer to Struct types IsZero() method. It panics if s's kind is not struct.
|
||||
func IsZero(s interface{}) bool {
|
||||
|
||||
-33
@@ -442,39 +442,6 @@ func TestValues_Anonymous(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNames(t *testing.T) {
|
||||
var T = struct {
|
||||
A string
|
||||
B int
|
||||
C bool
|
||||
}{
|
||||
A: "a-value",
|
||||
B: 2,
|
||||
C: true,
|
||||
}
|
||||
|
||||
s := Names(T)
|
||||
|
||||
if len(s) != 3 {
|
||||
t.Errorf("Names should return a slice of len 3, got: %d", len(s))
|
||||
}
|
||||
|
||||
inSlice := func(val string) bool {
|
||||
for _, v := range s {
|
||||
if reflect.DeepEqual(v, val) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
for _, val := range []string{"A", "B", "C"} {
|
||||
if !inSlice(val) {
|
||||
t.Errorf("Names should have the value %v", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFields(t *testing.T) {
|
||||
var T = struct {
|
||||
A string
|
||||
|
||||
+3
-3
@@ -89,7 +89,7 @@ func TestBucketOperations(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
if err.Error() != "403 Forbidden" {
|
||||
if err.Error() != "Access Denied" {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestBucketOperations(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
if err.Error() != "404 Not Found" {
|
||||
if err.Error() != "The specified bucket does not exist." {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func TestObjectOperations(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
if err.Error() != "404 Not Found" {
|
||||
if err.Error() != "The specified key does not exist." {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
}
|
||||
|
||||
+73
-6
@@ -335,7 +335,24 @@ func (a lowLevelAPI) headBucket(bucket string) error {
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// Head has no response body, handle it
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
var errorResponse ErrorResponse
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "NoSuchBucket",
|
||||
Message: "The specified bucket does not exist.",
|
||||
Resource: "/" + bucket,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
case resp.StatusCode == http.StatusForbidden:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "AccessDenied",
|
||||
Message: "Access Denied",
|
||||
Resource: "/" + bucket,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
}
|
||||
return errorResponse
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -367,8 +384,24 @@ func (a lowLevelAPI) deleteBucket(bucket string) error {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
// Head has no response body, handle it
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
var errorResponse ErrorResponse
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "NoSuchBucket",
|
||||
Message: "The specified bucket does not exist.",
|
||||
Resource: "/" + bucket,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
case resp.StatusCode == http.StatusForbidden:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "AccessDenied",
|
||||
Message: "Access Denied",
|
||||
Resource: "/" + bucket,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
}
|
||||
return errorResponse
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -512,7 +545,24 @@ func (a lowLevelAPI) deleteObject(bucket, object string) error {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
var errorResponse ErrorResponse
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "NoSuchKey",
|
||||
Message: "The specified key does not exist.",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
case resp.StatusCode == http.StatusForbidden:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "AccessDenied",
|
||||
Message: "Access Denied",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
}
|
||||
return errorResponse
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -545,7 +595,24 @@ func (a lowLevelAPI) headObject(bucket, object string) (ObjectStat, error) {
|
||||
defer resp.Body.Close()
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return ObjectStat{}, fmt.Errorf("%s", resp.Status)
|
||||
var errorResponse ErrorResponse
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "NoSuchKey",
|
||||
Message: "The specified key does not exist.",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
case resp.StatusCode == http.StatusForbidden:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "AccessDenied",
|
||||
Message: "Access Denied",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
}
|
||||
return ObjectStat{}, errorResponse
|
||||
}
|
||||
}
|
||||
md5sum := strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes
|
||||
@@ -594,7 +661,7 @@ func (a lowLevelAPI) listBuckets() (listAllMyBucketsResult, error) {
|
||||
if resp != nil {
|
||||
// for un-authenticated requests, amazon sends a redirect handle it
|
||||
if resp.StatusCode == http.StatusTemporaryRedirect {
|
||||
return listAllMyBucketsResult{}, fmt.Errorf("%s", resp.Status)
|
||||
return listAllMyBucketsResult{}, errors.New(resp.Status)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return listAllMyBucketsResult{}, responseToError(resp.Body)
|
||||
|
||||
+18
-1
@@ -230,7 +230,24 @@ func (a lowLevelAPI) abortMultipartUpload(bucket, object, uploadID string) error
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusNoContent {
|
||||
// Abort has no response body, handle it
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
var errorResponse ErrorResponse
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusNotFound:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "NoSuchUpload",
|
||||
Message: "The specified multipart upload does not exist.",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
case resp.StatusCode == http.StatusForbidden:
|
||||
errorResponse = ErrorResponse{
|
||||
Code: "AccessDenied",
|
||||
Message: "Access Denied",
|
||||
Resource: "/" + bucket + "/" + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
}
|
||||
}
|
||||
return errorResponse
|
||||
}
|
||||
}
|
||||
return resp.Body.Close()
|
||||
|
||||
+1
-1
@@ -308,7 +308,7 @@ func (cw *ansiColorWriter) Write(p []byte) (int, error) {
|
||||
}
|
||||
|
||||
if cw.state == outsideCsiCode {
|
||||
nw, err = cw.w.Write(p[first:])
|
||||
nw, err = cw.w.Write(p[first:len(p)])
|
||||
}
|
||||
|
||||
return r + nw + nc, err
|
||||
|
||||
@@ -51,6 +51,9 @@ release: getdeps verifiers
|
||||
@go run make.go install
|
||||
@mkdir -p $(HOME)/.mc
|
||||
|
||||
godepupdate:
|
||||
@for i in $(grep ImportPath Godeps/Godeps.json | grep -v minio/mc | cut -f2 -d: | sed -e 's/,//' -e 's/^[ \t]*//' -e 's/[ \t]*$//' -e 's/\"//g'); do godep update $i; done
|
||||
|
||||
save:
|
||||
@godep save ./...
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs {
|
||||
return &cpURLs{Error: iodine.New(err, nil)}
|
||||
}
|
||||
|
||||
// Source exist?
|
||||
// Source exists?
|
||||
sourceContent, err := sourceClient.Stat()
|
||||
if err != nil {
|
||||
// Source does not exist or insufficient privileges.
|
||||
@@ -134,12 +134,12 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs {
|
||||
// Source is not a regular file
|
||||
return &cpURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
}
|
||||
|
||||
targetClient, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
return &cpURLs{Error: iodine.New(err, nil)}
|
||||
}
|
||||
|
||||
// Target exist?
|
||||
// Target exists?
|
||||
targetContent, err := targetClient.Stat()
|
||||
if err == nil { // Target exists.
|
||||
if !targetContent.Type.IsRegular() { // Target is not a regular file
|
||||
@@ -148,6 +148,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) *cpURLs {
|
||||
}
|
||||
|
||||
// All OK.. We can proceed. Type A
|
||||
sourceContent.Name = sourceURL
|
||||
return &cpURLs{SourceContent: sourceContent, TargetContent: &client.Content{Name: targetURL}}
|
||||
}
|
||||
|
||||
@@ -213,13 +214,6 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *cpURLs {
|
||||
|
||||
// add `/` after trimming off `...` to emulate directories
|
||||
sourceURL = stripRecursiveURL(sourceURL)
|
||||
// is set when ... includes a directory, i.e. /path/to/dir... instead of path/to/dir/...
|
||||
recursivePrefix := ""
|
||||
if !strings.HasSuffix(sourceURL, string(filepath.Separator)) {
|
||||
recursivePrefix = filepath.Base(sourceURL)
|
||||
}
|
||||
sourceURL = strings.TrimSuffix(sourceURL, string(filepath.Separator)) + string(filepath.Separator)
|
||||
|
||||
sourceClient, err := source2Client(sourceURL)
|
||||
if err != nil {
|
||||
cpURLsCh <- &cpURLs{Error: iodine.New(err, nil)}
|
||||
@@ -285,16 +279,19 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *cpURLs {
|
||||
continue
|
||||
}
|
||||
|
||||
sourceContentParse, err := client.Parse(sourceURLParse.String() + sourceContent.Content.Name)
|
||||
sourceURLDelimited := sourceURLParse.String()[:strings.LastIndex(sourceURLParse.String(),
|
||||
string(sourceURLParse.Separator))+1]
|
||||
sourceContentName := sourceContent.Content.Name
|
||||
sourceContentURL := sourceURLDelimited + sourceContentName
|
||||
sourceContentParse, err := client.Parse(sourceContentURL)
|
||||
if err != nil {
|
||||
cpURLsCh <- &cpURLs{Error: iodine.New(errInvalidSource{URL: sourceContent.Content.Name}, nil)}
|
||||
cpURLsCh <- &cpURLs{Error: iodine.New(errInvalidSource{URL: sourceContentName}, nil)}
|
||||
continue
|
||||
}
|
||||
|
||||
// Construct target path from recursive path of source without its prefix dir.
|
||||
newTargetURLParse := *targetURLParse
|
||||
newTargetURLParse.Path = filepath.Join(newTargetURLParse.Path, recursivePrefix,
|
||||
strings.TrimPrefix(sourceContentParse.Path, filepath.Dir(sourceURLParse.Path)))
|
||||
newTargetURLParse.Path = filepath.Join(newTargetURLParse.Path, sourceContentName)
|
||||
cpURLsCh <- prepareCopyURLsTypeA(sourceContentParse.String(), newTargetURLParse.String())
|
||||
}
|
||||
}(sourceURL, targetURL, cpURLsCh)
|
||||
|
||||
@@ -38,13 +38,18 @@ const (
|
||||
func parseContent(c *client.Content) Content {
|
||||
content := Content{}
|
||||
content.Time = c.Time.Local().Format(printDate)
|
||||
|
||||
// guess file type
|
||||
content.Filetype = func() string {
|
||||
if c.Type.IsDir() {
|
||||
return "inode/directory"
|
||||
}
|
||||
return "application/octet-stream"
|
||||
}()
|
||||
|
||||
content.Size = humanize.IBytes(uint64(c.Size))
|
||||
|
||||
// Convert OS Type to match console file printing style
|
||||
content.Name = func() string {
|
||||
switch {
|
||||
case runtime.GOOS == "windows":
|
||||
|
||||
+30
-8
@@ -159,20 +159,29 @@ func (c *s3Client) SetBucketACL(acl string) error {
|
||||
func (c *s3Client) Stat() (*client.Content, error) {
|
||||
objectMetadata := new(client.Content)
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
switch {
|
||||
// valid case for s3:...
|
||||
case bucket == "" && object == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
return nil, iodine.New(bucket.Err, nil)
|
||||
}
|
||||
return &client.Content{Type: os.ModeDir}, nil
|
||||
}
|
||||
}
|
||||
if object != "" {
|
||||
metadata, err := c.api.StatObject(bucket, object)
|
||||
if err != nil {
|
||||
if err.Error() == "404 Not Found" {
|
||||
errResponse := s3.ToErrorResponse(err)
|
||||
if errResponse.Code == "NoSuchKey" {
|
||||
for content := range c.List(false) {
|
||||
if content.Err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
if !strings.HasPrefix(content.Content.Name, object) {
|
||||
content.Content.Type = os.ModeDir
|
||||
content.Content.Name = object
|
||||
content.Content.Size = 0
|
||||
return content.Content, nil
|
||||
}
|
||||
content.Content.Type = os.ModeDir
|
||||
content.Content.Name = object
|
||||
content.Content.Size = 0
|
||||
return content.Content, nil
|
||||
}
|
||||
}
|
||||
return nil, iodine.New(err, nil)
|
||||
@@ -336,7 +345,20 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
return
|
||||
}
|
||||
content := new(client.Content)
|
||||
normalizedKey := strings.TrimPrefix(object.Stat.Key, strings.TrimSuffix(o, delimiter)+delimiter)
|
||||
normalizedKey := object.Stat.Key
|
||||
switch {
|
||||
case o == "":
|
||||
// if no prefix provided and also URL is not delimited then we add bucket back into object name
|
||||
if strings.LastIndex(c.hostURL.Path, string(c.hostURL.Separator)) == 0 {
|
||||
if c.hostURL.String()[:strings.LastIndex(c.hostURL.String(), string(c.hostURL.Separator))+1] != b {
|
||||
normalizedKey = filepath.Join(b, object.Stat.Key)
|
||||
}
|
||||
}
|
||||
default:
|
||||
if strings.HasSuffix(o, delimiter) {
|
||||
normalizedKey = strings.TrimPrefix(object.Stat.Key, o)
|
||||
}
|
||||
}
|
||||
content.Name = normalizedKey
|
||||
content.Size = object.Stat.Size
|
||||
content.Time = object.Stat.LastModified
|
||||
|
||||
Reference in New Issue
Block a user