More prefix url cleanup

This commit is contained in:
Harshavardhana
2015-06-07 02:55:29 -07:00
parent 9f8040f645
commit 6c7dbcaf4e
2 changed files with 17 additions and 19 deletions
+7 -11
View File
@@ -213,13 +213,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 +278,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)
+10 -8
View File
@@ -162,17 +162,16 @@ func (c *s3Client) Stat() (*client.Content, error) {
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 +335,10 @@ 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
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