-
Notifications
You must be signed in to change notification settings - Fork 90
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
fix(index): close file before sign #1221
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -239,10 +239,11 @@ func (idx *Index) WriteArchiveIndex(ctx context.Context, destinationFile string) | |
if err != nil { | ||
return fmt.Errorf("failed to create archive file: %w", err) | ||
} | ||
defer outFile.Close() | ||
|
||
if _, err = io.Copy(outFile, archive); err != nil { | ||
return fmt.Errorf("failed to write contents to archive file: %w", err) | ||
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. Its not a super big deal, but you would leak a file descriptor here, wouldn't you? And "saying" that out loud, it looks like we must also be leaking 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. scratch that. it is just a io.Reader, which doens't have Close. So we do not need to close archive. |
||
} | ||
outFile.Close() | ||
|
||
if idx.SigningKey != "" { | ||
log.Infof("signing apk index at %s", idx.IndexFile) | ||
|
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 can't comment on lines that weren't changed, so I'm commenting here.
This function
WriteArchiveIndex
takes adestinationFile
, writes to that destinationFile and then signs the idx.IndexFile. So if they're not the same thing, then destinationFile won't actually get signed.There is only one caller of WriteArchiveIndex (GenerateIndex). So it feels like to me we should change WriteArchiveIndex to not take a destinationFile but rather just operate on idx.IndexFile rather than pretending it can do something else.
I admit I could be missing something here.