Skip to content
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

pkg/debuginfo: Set size of upload in upload initiation #1124

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/debuginfo/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (di *Manager) ensureUploaded(ctx context.Context, objFile *objectfile.Mappe
}

var r io.ReadSeeker
size := int64(0)

if di.stripDebuginfos {
if err := os.MkdirAll(di.tempDir, 0o755); err != nil {
Expand All @@ -201,6 +202,13 @@ func (di *Manager) ensureUploaded(ctx context.Context, objFile *objectfile.Mappe
if _, err := f.Seek(0, io.SeekStart); err != nil {
return fmt.Errorf("failed to seek to the beginning of the file: %w", err)
}

stat, err := f.Stat()
if err != nil {
return fmt.Errorf("failed to stat the file: %w", err)
}
size = stat.Size()

r = f
} else {
f, err := os.Open(src)
Expand All @@ -209,6 +217,12 @@ func (di *Manager) ensureUploaded(ctx context.Context, objFile *objectfile.Mappe
}
defer f.Close()

stat, err := f.Stat()
if err != nil {
return fmt.Errorf("failed to stat the file: %w", err)
}
size = stat.Size()

r = f
}

Expand All @@ -224,6 +238,7 @@ func (di *Manager) ensureUploaded(ctx context.Context, objFile *objectfile.Mappe
initiateResp, err := di.debuginfoClient.InitiateUpload(ctx, &debuginfopb.InitiateUploadRequest{
BuildId: buildID,
Hash: hash,
Size: size,
})
if err != nil {
if sts, ok := status.FromError(err); ok {
Expand Down