-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blob: TryReusingBlobWithOptions consider requiredCompression if set
TryReusingBlob now contains a new option `RequiredCompression` which filters the blob by checking against a compression of the blob which is considerd to be resued, in case `RequiredCompression` is set and `info` of the blob being reused does not matches, no blob is returned. Signed-off-by: Aditya R <[email protected]>
- Loading branch information
Showing
11 changed files
with
103 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package impl | ||
|
||
import ( | ||
"github.com/containers/image/v5/internal/private" | ||
compression "github.com/containers/image/v5/pkg/compression/types" | ||
) | ||
|
||
// BlobMatchesRequiredCompression validates if compression is required by the caller while selecting a blob, if it is required | ||
// then function performs a match against the compression requested by the caller and compression of existing blob | ||
// (which can be nil to represent uncompressed or unknown) | ||
func BlobMatchesRequiredCompression(options private.TryReusingBlobOptions, candidateCompression *compression.Algorithm) bool { | ||
if options.RequiredCompression == nil { | ||
return true // no requirement imposed | ||
} | ||
return candidateCompression != nil && (options.RequiredCompression.Name() == candidateCompression.Name()) | ||
} | ||
|
||
func OriginalBlobMatchesRequiredCompression(opts private.TryReusingBlobOptions) bool { | ||
return BlobMatchesRequiredCompression(opts, opts.OriginalCompression) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package impl | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/containers/image/v5/internal/private" | ||
"github.com/containers/image/v5/pkg/compression" | ||
compressionTypes "github.com/containers/image/v5/pkg/compression/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBlobMatchesRequiredCompression(t *testing.T) { | ||
var opts private.TryReusingBlobOptions | ||
cases := []struct { | ||
requiredCompression *compressionTypes.Algorithm | ||
candidateCompression *compressionTypes.Algorithm | ||
result bool | ||
}{ | ||
{&compression.Zstd, &compression.Zstd, true}, | ||
{&compression.Gzip, &compression.Zstd, false}, | ||
{&compression.Zstd, nil, false}, | ||
{nil, &compression.Zstd, true}, | ||
} | ||
|
||
for _, c := range cases { | ||
opts = private.TryReusingBlobOptions{RequiredCompression: c.requiredCompression} | ||
assert.Equal(t, BlobMatchesRequiredCompression(opts, c.candidateCompression), c.result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters