Don't return the from of a walk
Other storage drivers will only return children and below, s3 should do the same. The only reason it was returning was because of the addition of a / to ensure we treat the from as a directory. Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
This commit is contained in:
parent
fcc3632801
commit
fbb9c484d9
2 changed files with 17 additions and 14 deletions
|
@ -1044,18 +1044,8 @@ func (d *driver) Walk(ctx context.Context, from string, f storagedriver.WalkFn,
|
||||||
o(walkOptions)
|
o(walkOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
path := from
|
|
||||||
if !strings.HasSuffix(path, "/") {
|
|
||||||
path = path + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix := ""
|
|
||||||
if d.s3Path("") == "" {
|
|
||||||
prefix = "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
var objectCount int64
|
var objectCount int64
|
||||||
if err := d.doWalk(ctx, &objectCount, d.s3Path(path), prefix, walkOptions.StartAfterHint, f); err != nil {
|
if err := d.doWalk(ctx, &objectCount, from, walkOptions.StartAfterHint, f); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,7 +1057,7 @@ func (d *driver) Walk(ctx context.Context, from string, f storagedriver.WalkFn,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) doWalk(parentCtx context.Context, objectCount *int64, path, prefix string, startAfter string, f storagedriver.WalkFn) error {
|
func (d *driver) doWalk(parentCtx context.Context, objectCount *int64, from string, startAfter string, f storagedriver.WalkFn) error {
|
||||||
var (
|
var (
|
||||||
retError error
|
retError error
|
||||||
// the most recent directory walked for de-duping
|
// the most recent directory walked for de-duping
|
||||||
|
@ -1075,11 +1065,25 @@ func (d *driver) doWalk(parentCtx context.Context, objectCount *int64, path, pre
|
||||||
// the most recent skip directory to avoid walking over undesirable files
|
// the most recent skip directory to avoid walking over undesirable files
|
||||||
prevSkipDir string
|
prevSkipDir string
|
||||||
)
|
)
|
||||||
|
<<<<<<< HEAD
|
||||||
prevDir = strings.Replace(path, d.s3Path(""), prefix, 1)
|
prevDir = strings.Replace(path, d.s3Path(""), prefix, 1)
|
||||||
|
=======
|
||||||
|
prevDir = from
|
||||||
|
|
||||||
|
path := from
|
||||||
|
if !strings.HasSuffix(path, "/") {
|
||||||
|
path = path + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := ""
|
||||||
|
if d.s3Path("") == "" {
|
||||||
|
prefix = "/"
|
||||||
|
}
|
||||||
|
>>>>>>> 79bfef2e (Don't return the from of a walk)
|
||||||
|
|
||||||
listObjectsInput := &s3.ListObjectsV2Input{
|
listObjectsInput := &s3.ListObjectsV2Input{
|
||||||
Bucket: aws.String(d.Bucket),
|
Bucket: aws.String(d.Bucket),
|
||||||
Prefix: aws.String(path),
|
Prefix: aws.String(d.s3Path(path)),
|
||||||
MaxKeys: aws.Int64(listMax),
|
MaxKeys: aws.Int64(listMax),
|
||||||
StartAfter: aws.String(path + startAfter),
|
StartAfter: aws.String(path + startAfter),
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,7 +637,6 @@ func TestWalk(t *testing.T) {
|
||||||
name: "from folder",
|
name: "from folder",
|
||||||
fn: func(fileInfo storagedriver.FileInfo) error { return nil },
|
fn: func(fileInfo storagedriver.FileInfo) error { return nil },
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"/folder1",
|
|
||||||
"/folder1/file1",
|
"/folder1/file1",
|
||||||
},
|
},
|
||||||
from: "/folder1",
|
from: "/folder1",
|
||||||
|
|
Loading…
Reference in a new issue