Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Sep 23, 2024
1 parent 55c361a commit 5201cce
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions verifier/crl/crl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
)

const (
// tmpFileName is the prefix of the temporary file
tmpFileName = "notation-*"
// tempFileName is the prefix of the temporary file
tempFileName = "notation-*"
)

// FileCache implements corecrl.Cache.
Expand Down Expand Up @@ -148,27 +148,27 @@ func (c *FileCache) Set(ctx context.Context, url string, bundle *corecrl.Bundle)
content.DeltaCRL = bundle.DeltaCRL.Raw
}

// save content to tmp file
tmpFile, err := os.CreateTemp("", tmpFileName)
// save content to temp file
tempFile, err := os.CreateTemp("", tempFileName)
if err != nil {
return fmt.Errorf("failed to store crl bundle in file cache: failed to create tmpFile: %w", err)
return fmt.Errorf("failed to store crl bundle in file cache: failed to create temp file: %w", err)

Check warning on line 154 in verifier/crl/crl.go

View check run for this annotation

Codecov / codecov/patch

verifier/crl/crl.go#L154

Added line #L154 was not covered by tests
}
defer func() {
if err := tmpFile.Close(); err != nil && setErr == nil {
setErr = fmt.Errorf("failed to close tmpFile while storing crl bundle in file cache: %w", err)
}
// remove the tmp file in case of error.
// remove the temp file in case of error
if setErr != nil {
defer os.Remove(tmpFile.Name())
defer os.Remove(tempFile.Name())
}
}()

if err := json.NewEncoder(tmpFile).Encode(content); err != nil {
if err := json.NewEncoder(tempFile).Encode(content); err != nil {
return fmt.Errorf("failed to store crl bundle in file cache: failed to encode content: %w", err)

Check warning on line 164 in verifier/crl/crl.go

View check run for this annotation

Codecov / codecov/patch

verifier/crl/crl.go#L164

Added line #L164 was not covered by tests
}
if err := tempFile.Close(); err != nil {
return fmt.Errorf("failed to store crl bundle in file cache: failed to close temp file: %w", err)

Check warning on line 167 in verifier/crl/crl.go

View check run for this annotation

Codecov / codecov/patch

verifier/crl/crl.go#L167

Added line #L167 was not covered by tests
}

// rename is atomic on UNIX-like platforms
if err := os.Rename(tmpFile.Name(), filepath.Join(c.root, c.fileName(url))); err != nil {
if err := os.Rename(tempFile.Name(), filepath.Join(c.root, c.fileName(url))); err != nil {
return fmt.Errorf("failed to store crl bundle in file cache: %w", err)
}
return nil
Expand Down

0 comments on commit 5201cce

Please sign in to comment.