Skip to content

Commit

Permalink
endpoint: qiniu: Fix object not found
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Mar 20, 2018
1 parent 701ef50 commit c2e9d0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
7 changes: 2 additions & 5 deletions endpoint/qiniu/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"net/http"
"path"
"strings"

"github.com/qiniu/api.v7/auth/qbox"
Expand Down Expand Up @@ -107,11 +106,9 @@ func New(ctx context.Context, et uint8) (c *Client, err error) {

// Stat implement source.Stat and destination.Stat
func (c *Client) Stat(ctx context.Context, p string) (o *model.Object, err error) {
cp := path.Join(c.Path, p)
// Trim left "/" to prevent object start with "/"
cp = strings.TrimLeft(cp, "/")
cp := utils.Join(c.Path, p)

fi, err := c.bucket.Stat(c.BucketName, p)
fi, err := c.bucket.Stat(c.BucketName, cp)
if err != nil {
if e, ok := err.(*rpc.ErrorInfo); ok {
// If object not found, we just need to return a nil object.
Expand Down
18 changes: 5 additions & 13 deletions endpoint/qiniu/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package qiniu
import (
"context"
"io"
"path"
"strings"
"time"

"github.com/qiniu/api.v7/storage"
"github.com/sirupsen/logrus"

"github.com/yunify/qscamel/model"
"github.com/yunify/qscamel/utils"
)

// Reachable implement source.Reachable
Expand All @@ -27,10 +26,7 @@ func (c *Client) Readable() bool {
func (c *Client) List(ctx context.Context, j *model.Job, rc chan *model.Object) {
defer close(rc)

// Add "/" to list specific prefix.
cp := path.Join(c.Path, j.Path) + "/"
// Trim left "/" to prevent object start with "/"
cp = strings.TrimLeft(cp, "/")
cp := utils.Join(c.Path, j.Path) + "/"

marker := j.Marker

Expand All @@ -43,7 +39,7 @@ func (c *Client) List(ctx context.Context, j *model.Job, rc chan *model.Object)
}
for _, v := range entries {
object := &model.Object{
Key: strings.TrimLeft(v.Key, c.Path),
Key: utils.Relative(v.Key, c.Path),
IsDir: false,
Size: v.Fsize,
}
Expand Down Expand Up @@ -72,9 +68,7 @@ func (c *Client) List(ctx context.Context, j *model.Job, rc chan *model.Object)

// Read implement source.Read
func (c *Client) Read(ctx context.Context, p string) (r io.ReadCloser, err error) {
cp := path.Join(c.Path, p)
// Trim left "/" to prevent object start with "/"
cp = strings.TrimLeft(cp, "/")
cp := utils.Join(c.Path, p)

deadline := time.Now().Add(time.Hour).Unix()
url := storage.MakePrivateURL(c.mac, c.Domain, cp, deadline)
Expand All @@ -90,9 +84,7 @@ func (c *Client) Read(ctx context.Context, p string) (r io.ReadCloser, err error

// Reach implement source.Fetch
func (c *Client) Reach(ctx context.Context, p string) (url string, err error) {
cp := path.Join(c.Path, p)
// Trim left "/" to prevent object start with "/"
cp = strings.TrimLeft(cp, "/")
cp := utils.Join(c.Path, p)

deadline := time.Now().Add(time.Hour).Unix()
url = storage.MakePrivateURL(c.mac, c.Domain, cp, deadline)
Expand Down

0 comments on commit c2e9d0c

Please sign in to comment.