Skip to content

Commit

Permalink
Merge pull request #1039 from jonjohnsonjr/no-temp-sign-index
Browse files Browse the repository at this point in the history
Don't write APK to temp file during signing
  • Loading branch information
jonjohnsonjr authored Feb 20, 2024
2 parents e957ab1 + afaebbc commit 5f1f44c
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions pkg/cli/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (o signOpts) run(ctx context.Context, pkg string) error {
if err != nil {
return err
}
defer cf.Close()

// Use the control sections ModTime (set to SDE) for the signature
cfinfo, err := os.Stat(eapk.ControlFile)
Expand Down Expand Up @@ -242,26 +243,7 @@ func (o signOpts) run(ctx context.Context, pkg string) error {
if err != nil {
return err
}

tf, err := os.CreateTemp("", "melange-signer")
if err != nil {
return err
}
defer os.RemoveAll(tf.Name())

for _, fp := range []io.Reader{bytes.NewBuffer(sigData), cf, df} {
if _, err := io.Copy(tf, fp); err != nil {
return err
}
}

if err := tf.Sync(); err != nil {
return err
}

if _, err := tf.Seek(0, io.SeekStart); err != nil {
return err
}
defer df.Close()

// Replace the package file with the new one
f, err := os.Create(pkg)
Expand All @@ -270,8 +252,10 @@ func (o signOpts) run(ctx context.Context, pkg string) error {
}
defer f.Close()

if _, err := io.Copy(f, tf); err != nil {
return err
for _, fp := range []io.Reader{bytes.NewBuffer(sigData), cf, df} {
if _, err := io.Copy(f, fp); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 5f1f44c

Please sign in to comment.