-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(storage/transfermanager): add SkipIfExists option #10893
Changes from 1 commit
e6d6078
f902816
416ead9
ecfbda2
a55570d
4eb73e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
@@ -295,6 +296,75 @@ func TestIntegration_DownloadDirectoryAsync(t *testing.T) { | |
t.Errorf("unexpected file %q in dir", entry.Name()) | ||
} | ||
} | ||
|
||
// Now attempt to download the entire directory. | ||
// The existing files should be skipped. | ||
callbacks := make(chan bool) | ||
|
||
d, err = NewDownloader(c, WithWorkers(2), SkipIfExists()) | ||
if err != nil { | ||
t.Fatalf("NewDownloader: %v", err) | ||
} | ||
|
||
if err := d.DownloadDirectory(ctx, &DownloadDirectoryInput{ | ||
Bucket: tb.bucket, | ||
LocalDirectory: localDir, | ||
OnObjectDownload: func(got *DownloadOutput) { | ||
callbacks <- true | ||
|
||
if got.Err != nil { | ||
t.Errorf("result.Err: %v", got.Err) | ||
} | ||
|
||
if strings.EqualFold(got.Object, "dir/objA") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
t.Errorf("should have skipped download of object %s", got.Object) | ||
} | ||
|
||
if got, want := got.Attrs.Size, tb.objectSizes[got.Object]; want != got { | ||
t.Errorf("expected object size %d, got %d", want, got) | ||
} | ||
|
||
path := filepath.Join(localDir, got.Object) | ||
f, err := os.Open(path) | ||
if err != nil { | ||
t.Errorf("os.Open(%q): %v", path, err) | ||
} | ||
defer f.Close() | ||
|
||
b := bytes.NewBuffer(make([]byte, 0, got.Attrs.Size)) | ||
if _, err := io.Copy(b, f); err != nil { | ||
t.Errorf("io.Copy: %v", err) | ||
} | ||
|
||
if wantCRC, gotCRC := tb.contentHashes[got.Object], crc32c(b.Bytes()); gotCRC != wantCRC { | ||
t.Errorf("object(%q) at filepath(%q): content crc32c does not match; got: %v, expected: %v", got.Object, path, gotCRC, wantCRC) | ||
} | ||
}, | ||
}); err != nil { | ||
t.Errorf("d.DownloadDirectory: %v", err) | ||
} | ||
|
||
gotCallbacks := 0 | ||
done := make(chan bool) | ||
go func() { | ||
for { | ||
select { | ||
case <-done: | ||
break | ||
case <-callbacks: | ||
gotCallbacks++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my learning, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I re-wrote that logic, PTAL. |
||
} | ||
} | ||
}() | ||
|
||
if _, err := d.WaitAndClose(); err != nil { | ||
t.Errorf("d.WaitAndClose: %v", err) | ||
} | ||
done <- true | ||
|
||
if want, got := len(tb.objects)-wantObjs, gotCallbacks; want != got { | ||
t.Errorf("expected to receive %d callbacks, got %d", want, got) | ||
BrennaEpp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help to clarify that you're checking that SkipIfExists() should not attempt downloading included files from previous directory download;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment here and put those objects in a variable - does that seem sufficient here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you;