Skip to content

Commit

Permalink
signer: gpg2: warn when cleaning up temp files and dirs after signing…
Browse files Browse the repository at this point in the history
… fails
  • Loading branch information
Greg Guthe committed Oct 7, 2021
1 parent b8962b7 commit 142025d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions signer/gpg2/gpg2.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ func (s *GPG2Signer) SignData(data []byte, options interface{}) (signer.Signatur
if err != nil {
return nil, fmt.Errorf("gpg2: failed to create tempfile for input to sign: %w", err)
}
defer os.Remove(tmpContentFile.Name())
defer func() {
if err := os.Remove(tmpContentFile.Name()); err != nil {
log.Infof("gpg2: error removing content file %q: %q", tmpContentFile.Name(), err)
}
}()
err = ioutil.WriteFile(tmpContentFile.Name(), data, 0755)
if err != nil {
return nil, fmt.Errorf("gpg2: failed to write tempfile for input to sign: %w", err)
Expand Down Expand Up @@ -391,7 +395,11 @@ func (s *GPG2Signer) SignFiles(inputs []signer.NamedUnsignedFile, options interf
err = fmt.Errorf("gpg2: error creating tempdir for debsign: %w", err)
return
}
defer os.RemoveAll(inputsTmpDir)
defer func() {
if err := os.RemoveAll(inputsTmpDir); err != nil {
log.Infof("gpg2: error removing sign files inputs directory %q: %q", inputsTmpDir, err)
}
}()

// write the inputs to their tmp dir
var inputFilePaths []string
Expand Down

0 comments on commit 142025d

Please sign in to comment.