Skip to content

Commit

Permalink
Use the Go 1.19 type-safe sync/atomic type
Browse files Browse the repository at this point in the history
... which makes sure the value is not accessed directly.

Should not change behavior (the new function calls the previous
implementation internally).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Aug 4, 2023
1 parent b7cb1ae commit 25f6e6f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions storage/storage_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type storageImageDestination struct {

imageRef storageReference
directory string // Temporary directory where we store blobs until Commit() time
nextTempFileID int32 // A counter that we use for computing filenames to assign to blobs
nextTempFileID atomic.Int32 // A counter that we use for computing filenames to assign to blobs
manifest []byte // Manifest contents, temporary
manifestDigest digest.Digest // Valid if len(manifest) != 0
signatures []byte // Signature contents, temporary
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *storageImageDestination) Close() error {
}

func (s *storageImageDestination) computeNextBlobCacheFile() string {
return filepath.Join(s.directory, fmt.Sprintf("%d", atomic.AddInt32(&s.nextTempFileID, 1)))
return filepath.Join(s.directory, fmt.Sprintf("%d", s.nextTempFileID.Add(1)))
}

// PutBlobWithOptions writes contents of stream and returns data representing the result.
Expand Down

0 comments on commit 25f6e6f

Please sign in to comment.