storage/driver/s3: adjust s3 driver to return unmunged path

This fixes both the s3 driver and the oss driver to return the unmunged path
when returning errors.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-12-08 11:02:40 -08:00
parent b6756a3d89
commit 66cd2bf950
2 changed files with 23 additions and 17 deletions

View file

@ -651,8 +651,9 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
}
// List returns a list of the objects that are direct descendants of the given path.
func (d *driver) List(ctx context.Context, path string) ([]string, error) {
if path != "/" && path[len(path)-1] != '/' {
func (d *driver) List(ctx context.Context, opath string) ([]string, error) {
path := opath
if path != "/" && opath[len(path)-1] != '/' {
path = path + "/"
}
@ -666,13 +667,7 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
listResponse, err := d.Bucket.List(d.ossPath(path), "/", "", listMax)
if err != nil {
return nil, parseError(path, err)
}
if len(listResponse.Contents) == 0 && path != "/" {
// Treat empty response as missing directory, since we don't actually
// have directories in OSS.
return nil, storagedriver.PathNotFoundError{Path: path}
return nil, parseError(opath, err)
}
files := []string{}
@ -697,6 +692,14 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
}
}
if opath != "/" {
if len(files) == 0 && len(directories) == 0 {
// Treat empty response as missing directory, since we don't actually
// have directories in s3.
return nil, storagedriver.PathNotFoundError{Path: opath}
}
}
return append(files, directories...), nil
}

View file

@ -667,7 +667,8 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
}
// List returns a list of the objects that are direct descendants of the given path.
func (d *driver) List(ctx context.Context, path string) ([]string, error) {
func (d *driver) List(ctx context.Context, opath string) ([]string, error) {
path := opath
if path != "/" && path[len(path)-1] != '/' {
path = path + "/"
}
@ -682,13 +683,7 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
listResponse, err := d.Bucket.List(d.s3Path(path), "/", "", listMax)
if err != nil {
return nil, err
}
if len(listResponse.Contents) == 0 {
// Treat empty response as missing directory, since we don't actually
// have directories in s3.
return nil, storagedriver.PathNotFoundError{Path: path}
return nil, parseError(opath, err)
}
files := []string{}
@ -713,6 +708,14 @@ func (d *driver) List(ctx context.Context, path string) ([]string, error) {
}
}
if opath != "/" {
if len(files) == 0 && len(directories) == 0 {
// Treat empty response as missing directory, since we don't actually
// have directories in s3.
return nil, storagedriver.PathNotFoundError{Path: opath}
}
}
return append(files, directories...), nil
}