Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gofumpt #2500

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
run:
concurrency: 6
timeout: 5m

linters:
enable:
- gofmt
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ clean:
test:
@go test $(BUILDFLAGS) -cover ./...

fmt:
@gofmt -l -s -w $(SOURCE_DIRS)

validate: lint
@BUILDTAGS="$(BUILDTAGS)" hack/validate.sh

Expand Down
3 changes: 2 additions & 1 deletion copy/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
// and returns a complete blobInfo of the copied blob.
func (ic *imageCopier) copyBlobFromStream(ctx context.Context, srcReader io.Reader, srcInfo types.BlobInfo,
getOriginalLayerCopyWriter func(decompressor compressiontypes.DecompressorFunc) io.Writer,
isConfig bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool) (types.BlobInfo, error) {
isConfig bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool,
) (types.BlobInfo, error) {
// The copying happens through a pipeline of connected io.Readers;
// that pipeline is built by updating stream.
// === Input: srcReader
Expand Down
9 changes: 6 additions & 3 deletions copy/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const (
// Returns data for other steps; the caller should eventually call updateCompressionEdits and perhaps recordValidatedBlobData,
// and must eventually call close.
func (ic *imageCopier) blobPipelineCompressionStep(stream *sourceStream, canModifyBlob bool, srcInfo types.BlobInfo,
detected bpDetectCompressionStepData) (*bpCompressionStepData, error) {
detected bpDetectCompressionStepData,
) (*bpCompressionStepData, error) {
// WARNING: If you are adding new reasons to change the blob, update also the OptimizeDestinationImageAlreadyExists
// short-circuit conditions
layerCompressionChangeSupported := ic.src.CanChangeLayerCompression(stream.info.MediaType)
Expand Down Expand Up @@ -264,7 +265,8 @@ func (ic *imageCopier) bpcDecompressCompressed(stream *sourceStream, detected bp
// This does not change the sourceStream parameter; we include it for symmetry with other
// pipeline steps.
func (ic *imageCopier) bpcPreserveOriginal(_ *sourceStream, detected bpDetectCompressionStepData,
layerCompressionChangeSupported bool) *bpCompressionStepData {
layerCompressionChangeSupported bool,
) *bpCompressionStepData {
logrus.Debugf("Using original blob without modification")
// Remember if the original blob was compressed, and if so how, so that if
// LayerInfosForCopy() returned something that differs from what was in the
Expand Down Expand Up @@ -319,7 +321,8 @@ func (d *bpCompressionStepData) updateCompressionEdits(operation *types.LayerCom
// and the original srcInfo (which the caller guarantees has been validated).
// This must ONLY be called if all data has been validated by OUR code, and is not coming from third parties.
func (d *bpCompressionStepData) recordValidatedDigestData(c *copier, uploadedInfo types.BlobInfo, srcInfo types.BlobInfo,
encryptionStep *bpEncryptionStepData, decryptionStep *bpDecryptionStepData) error {
encryptionStep *bpEncryptionStepData, decryptionStep *bpDecryptionStepData,
) error {
// Don’t record any associations that involve encrypted data. This is a bit crude,
// some blob substitutions (replacing pulls of encrypted data with local reuse of known decryption outcomes)
// might be safe, but it’s not trivially obvious, so let’s be conservative for now.
Expand Down
3 changes: 2 additions & 1 deletion copy/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ type bpEncryptionStepData struct {
// srcInfo is primarily used for error messages.
// Returns data for other steps; the caller should eventually call updateCryptoOperationAndAnnotations.
func (ic *imageCopier) blobPipelineEncryptionStep(stream *sourceStream, toEncrypt bool, srcInfo types.BlobInfo,
decryptionStep *bpDecryptionStepData) (*bpEncryptionStepData, error) {
decryptionStep *bpDecryptionStepData,
) (*bpEncryptionStepData, error) {
if !toEncrypt || isOciEncrypted(srcInfo.MediaType) || ic.c.options.OciEncryptConfig == nil {
return &bpEncryptionStepData{
encrypting: false,
Expand Down
9 changes: 6 additions & 3 deletions copy/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func TestDetermineManifestConversion(t *testing.T) {
},
// Conversion necessary, a preferred format is not acceptable
{
"s2→OCI", manifest.DockerV2Schema2MediaType, []string{v1.MediaTypeImageManifest},
"s2→OCI", manifest.DockerV2Schema2MediaType,
[]string{v1.MediaTypeImageManifest},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file: The line breaks are currently consistent across the table… and shorter entries, even if wider help scanning.

manifestConversionPlan{
preferredMIMEType: v1.MediaTypeImageManifest,
preferredMIMETypeNeedsConversion: true,
Expand All @@ -135,7 +136,8 @@ func TestDetermineManifestConversion(t *testing.T) {
},
// text/plain is converted if the destination does not accept s1
{
"text→s2", "text/plain", []string{manifest.DockerV2Schema2MediaType},
"text→s2", "text/plain",
[]string{manifest.DockerV2Schema2MediaType},
manifestConversionPlan{
preferredMIMEType: manifest.DockerV2Schema2MediaType,
preferredMIMETypeNeedsConversion: true,
Expand All @@ -162,7 +164,8 @@ func TestDetermineManifestConversion(t *testing.T) {
},
},
{
"special→OCI", manifest.DockerV2ListMediaType, []string{v1.MediaTypeImageManifest, "other options", "with lower priority"},
"special→OCI", manifest.DockerV2ListMediaType,
[]string{v1.MediaTypeImageManifest, "other options", "with lower priority"},
manifestConversionPlan{
preferredMIMEType: v1.MediaTypeImageManifest,
preferredMIMETypeNeedsConversion: true,
Expand Down
11 changes: 7 additions & 4 deletions copy/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func platformV1ToPlatformComparable(platform *imgspecv1.Platform) platformCompar
}
osFeatures := slices.Clone(platform.OSFeatures)
sort.Strings(osFeatures)
return platformComparable{architecture: platform.Architecture,
os: platform.OS,
return platformComparable{
architecture: platform.Architecture,
os: platform.OS,
// This is strictly speaking ambiguous, fields of OSFeatures can contain a ','. Probably good enough for now.
osFeatures: strings.Join(osFeatures, ","),
osVersion: platform.OSVersion,
Expand Down Expand Up @@ -252,15 +253,17 @@ func (c *copier) copyMultipleImages(ctx context.Context) (copiedManifest []byte,
UpdateDigest: updated.manifestDigest,
UpdateSize: int64(len(updated.manifest)),
UpdateCompressionAlgorithms: updated.compressionAlgorithms,
UpdateMediaType: updated.manifestMIMEType})
UpdateMediaType: updated.manifestMIMEType,
})
case instanceCopyClone:
logrus.Debugf("Replicating instance %s (%d/%d)", instance.sourceDigest, i+1, len(instanceCopyList))
c.Printf("Replicating image %s (%d/%d)\n", instance.sourceDigest, i+1, len(instanceCopyList))
unparsedInstance := image.UnparsedInstance(c.rawSource, &instanceCopyList[i].sourceDigest)
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, copySingleImageOptions{
requireCompressionFormatMatch: true,
compressionFormat: &instance.cloneCompressionVariant.Algorithm,
compressionLevel: instance.cloneCompressionVariant.Level})
compressionLevel: instance.cloneCompressionVariant.Level,
})
if err != nil {
return nil, fmt.Errorf("replicating image %d/%d from manifest list: %w", i+1, len(instanceCopyList), err)
}
Expand Down
32 changes: 21 additions & 11 deletions copy/multiple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ func TestPrepareCopyInstancesforInstanceCopyCopy(t *testing.T) {
compare := []instanceCopy{}

for _, instance := range sourceInstances {
compare = append(compare, instanceCopy{op: instanceCopyCopy,
sourceDigest: instance, copyForceCompressionFormat: false})
compare = append(compare, instanceCopy{
op: instanceCopyCopy,
sourceDigest: instance, copyForceCompressionFormat: false,
})
}
assert.Equal(t, instancesToCopy, compare)

// Test CopySpecificImages where selected instance is sourceInstances[1]
instancesToCopy, err = prepareInstanceCopies(list, sourceInstances, &Options{Instances: []digest.Digest{sourceInstances[1]}, ImageListSelection: CopySpecificImages})
require.NoError(t, err)
compare = []instanceCopy{{op: instanceCopyCopy,
sourceDigest: sourceInstances[1]}}
compare = []instanceCopy{{
op: instanceCopyCopy,
sourceDigest: sourceInstances[1],
}}
assert.Equal(t, instancesToCopy, compare)

_, err = prepareInstanceCopies(list, sourceInstances, &Options{Instances: []digest.Digest{sourceInstances[1]}, ImageListSelection: CopySpecificImages, ForceCompressionFormat: true})
Expand All @@ -64,9 +68,11 @@ func TestPrepareCopyInstancesforInstanceCopyClone(t *testing.T) {
}

// CopySpecificImage must fail with error
_, err = prepareInstanceCopies(list, sourceInstances, &Options{EnsureCompressionVariantsExist: ensureCompressionVariantsExist,
Instances: []digest.Digest{sourceInstances[1]},
ImageListSelection: CopySpecificImages})
_, err = prepareInstanceCopies(list, sourceInstances, &Options{
EnsureCompressionVariantsExist: ensureCompressionVariantsExist,
Instances: []digest.Digest{sourceInstances[1]},
ImageListSelection: CopySpecificImages,
})
require.EqualError(t, err, "EnsureCompressionVariantsExist is not implemented for CopySpecificImages")

// Test copying all images with replication
Expand All @@ -83,8 +89,10 @@ func TestPrepareCopyInstancesforInstanceCopyClone(t *testing.T) {
// and still copy `sourceInstance[2]`.
expectedResponse := []simplerInstanceCopy{}
for _, instance := range sourceInstances {
expectedResponse = append(expectedResponse, simplerInstanceCopy{op: instanceCopyCopy,
sourceDigest: instance})
expectedResponse = append(expectedResponse, simplerInstanceCopy{
op: instanceCopyCopy,
sourceDigest: instance,
})
// If its `arm64` and sourceDigest[2] , expect a clone to happen
if instance == sourceInstances[2] {
expectedResponse = append(expectedResponse, simplerInstanceCopy{op: instanceCopyClone, sourceDigest: instance, cloneCompressionVariant: "zstd", clonePlatform: "arm64-linux-"})
Expand All @@ -100,8 +108,10 @@ func TestPrepareCopyInstancesforInstanceCopyClone(t *testing.T) {
require.NoError(t, err)
expectedResponse = []simplerInstanceCopy{}
for _, instance := range sourceInstances {
expectedResponse = append(expectedResponse, simplerInstanceCopy{op: instanceCopyCopy,
sourceDigest: instance})
expectedResponse = append(expectedResponse, simplerInstanceCopy{
op: instanceCopyCopy,
sourceDigest: instance,
})
// If its `arm64` and sourceDigest[2] , expect a clone to happen
if instance == sourceInstances[2] {
expectedResponse = append(expectedResponse, simplerInstanceCopy{op: instanceCopyClone, sourceDigest: instance, cloneCompressionVariant: "zstd", clonePlatform: "arm64-linux-"})
Expand Down
1 change: 0 additions & 1 deletion copy/progress_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ func TestReadWithEvent(t *testing.T) {
read, err := reader.Read(b)
assert.Equal(t, read, 5)
assert.Nil(t, err)

}
3 changes: 2 additions & 1 deletion copy/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (c *copier) setupSigners() error {
// and verifies that they can be used (to avoid copying a large image when we
// can tell in advance that it would ultimately fail)
func (c *copier) sourceSignatures(ctx context.Context, unparsed private.UnparsedImage,
gettingSignaturesMessage, checkingDestMessage string) ([]internalsig.Signature, error) {
gettingSignaturesMessage, checkingDestMessage string,
) ([]internalsig.Signature, error) {
var sigs []internalsig.Signature
if c.options.RemoveSignatures {
sigs = []internalsig.Signature{}
Expand Down
3 changes: 2 additions & 1 deletion copy/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@ func updatedBlobInfoFromReuse(inputInfo types.BlobInfo, reusedBlob private.Reuse
// perhaps (de/re/)compressing the stream,
// and returns a complete blobInfo of the copied blob and perhaps a <-chan diffIDResult if diffIDIsNeeded, to be read by the caller.
func (ic *imageCopier) copyLayerFromStream(ctx context.Context, srcStream io.Reader, srcInfo types.BlobInfo,
diffIDIsNeeded bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool) (types.BlobInfo, <-chan diffIDResult, error) {
diffIDIsNeeded bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool,
) (types.BlobInfo, <-chan diffIDResult, error) {
var getDiffIDRecorder func(compressiontypes.DecompressorFunc) io.Writer // = nil
var diffIDChan chan diffIDResult

Expand Down
10 changes: 5 additions & 5 deletions directory/directory_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func newImageDestination(sys *types.SystemContext, ref dirReference) (private.Im
}
} else {
// create directory if it doesn't exist
if err := os.MkdirAll(ref.resolvedPath, 0755); err != nil {
if err := os.MkdirAll(ref.resolvedPath, 0o755); err != nil {
return nil, fmt.Errorf("unable to create directory %q: %w", ref.resolvedPath, err)
}
}
// create version file
err = os.WriteFile(ref.versionPath(), []byte(version), 0644)
err = os.WriteFile(ref.versionPath(), []byte(version), 0o644)
if err != nil {
return nil, fmt.Errorf("creating version file %q: %w", ref.versionPath(), err)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (d *dirImageDestination) PutBlobWithOptions(ctx context.Context, stream io.
// ignored and the file is already readable; besides, blobFile.Chmod, i.e. syscall.Fchmod,
// always fails on Windows.
if runtime.GOOS != "windows" {
if err := blobFile.Chmod(0644); err != nil {
if err := blobFile.Chmod(0o644); err != nil {
return private.UploadedBlob{}, err
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (d *dirImageDestination) PutManifest(ctx context.Context, manifest []byte,
if err != nil {
return err
}
return os.WriteFile(path, manifest, 0644)
return os.WriteFile(path, manifest, 0o644)
}

// PutSignaturesWithFormat writes a set of signatures to the destination.
Expand All @@ -244,7 +244,7 @@ func (d *dirImageDestination) PutSignaturesWithFormat(ctx context.Context, signa
if err != nil {
return err
}
if err := os.WriteFile(path, blob, 0644); err != nil {
if err := os.WriteFile(path, blob, 0o644); err != nil {
return err
}
}
Expand Down
6 changes: 4 additions & 2 deletions directory/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"github.com/stretchr/testify/require"
)

var _ private.ImageSource = (*dirImageSource)(nil)
var _ private.ImageDestination = (*dirImageDestination)(nil)
var (
_ private.ImageSource = (*dirImageSource)(nil)
_ private.ImageDestination = (*dirImageDestination)(nil)
)

func TestDestinationReference(t *testing.T) {
ref, tmpDir := refToTempDir(t)
Expand Down
20 changes: 10 additions & 10 deletions directory/explicitfilepath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type pathResolvingTestCase struct {
var testCases = []pathResolvingTestCase{
{ // A straightforward subdirectory hierarchy
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0o755)
require.NoError(t, err)
return "dir1/dir2/dir3"
},
Expand All @@ -33,7 +33,7 @@ var testCases = []pathResolvingTestCase{
},
{ // Symlink on the path
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0o755)
require.NoError(t, err)
err = os.Symlink("dir1", filepath.Join(top, "link1"))
require.NoError(t, err)
Expand All @@ -43,7 +43,7 @@ var testCases = []pathResolvingTestCase{
},
{ // Trailing symlink
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0o755)
require.NoError(t, err)
err = os.Symlink("dir2", filepath.Join(top, "dir1/link2"))
require.NoError(t, err)
Expand All @@ -69,23 +69,23 @@ var testCases = []pathResolvingTestCase{
},
{ // Relative components in a path
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0o755)
require.NoError(t, err)
return "dir1/./dir2/../dir2/dir3"
},
"dir1/dir2/dir3",
},
{ // Trailing relative components
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0o755)
require.NoError(t, err)
return "dir1/dir2/.."
},
"dir1",
},
{ // Relative components in symlink
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2"), 0o755)
require.NoError(t, err)
err = os.Symlink("../dir1/dir2", filepath.Join(top, "dir1/link2"))
require.NoError(t, err)
Expand All @@ -95,7 +95,7 @@ var testCases = []pathResolvingTestCase{
},
{ // Relative component pointing "into" a symlink
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0755)
err := os.MkdirAll(filepath.Join(top, "dir1/dir2/dir3"), 0o755)
require.NoError(t, err)
err = os.Symlink("dir3", filepath.Join(top, "dir1/dir2/link3"))
require.NoError(t, err)
Expand All @@ -105,9 +105,9 @@ var testCases = []pathResolvingTestCase{
},
{ // Unreadable directory
func(t *testing.T, top string) string {
err := os.MkdirAll(filepath.Join(top, "unreadable/dir2"), 0755)
err := os.MkdirAll(filepath.Join(top, "unreadable/dir2"), 0o755)
require.NoError(t, err)
err = os.Chmod(filepath.Join(top, "unreadable"), 000)
err = os.Chmod(filepath.Join(top, "unreadable"), 0o00)
require.NoError(t, err)
return "unreadable/dir2"
},
Expand All @@ -127,7 +127,7 @@ func runPathResolvingTestCase(t *testing.T, f func(string) (string, error), c pa
topDir := t.TempDir()
defer func() {
// Clean up after the "Unreadable directory" case; os.RemoveAll just fails without this.
_ = os.Chmod(filepath.Join(topDir, "unreadable"), 0755) // Ignore errors, especially if this does not exist.
_ = os.Chmod(filepath.Join(topDir, "unreadable"), 0o755) // Ignore errors, especially if this does not exist.
}()

input := c.setup(t, topDir) + suffix // Do not call filepath.Join() on input, it calls filepath.Clean() internally!
Expand Down
3 changes: 2 additions & 1 deletion docker/archive/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func NewIndexReference(path string, sourceIndex int) (types.ImageReference, erro
// newReference returns a docker archive reference for a path, an optional reference or sourceIndex,
// and optionally a tarfile.Reader and/or a tarfile.Writer matching path.
func newReference(path string, ref reference.NamedTagged, sourceIndex int,
archiveReader *tarfile.Reader, writer *Writer) (types.ImageReference, error) {
archiveReader *tarfile.Reader, writer *Writer,
) (types.ImageReference, error) {
if strings.Contains(path, ":") {
return nil, fmt.Errorf("Invalid docker-archive: reference: colon in path %q is not supported", path)
}
Expand Down
2 changes: 1 addition & 1 deletion docker/archive/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestReferenceDeleteImage(t *testing.T) {

for i, suffix := range []string{"", ":some-reference", ":@0"} {
testFile := filepath.Join(tmpDir, fmt.Sprintf("file%d.tar", i))
err := os.WriteFile(testFile, []byte("nonempty"), 0644)
err := os.WriteFile(testFile, []byte("nonempty"), 0o644)
require.NoError(t, err, suffix)

ref, err := ParseReference(testFile + suffix)
Expand Down
2 changes: 1 addition & 1 deletion docker/archive/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewWriter(sys *types.SystemContext, path string) (*Writer, error) {
// in the case of a regular file, we don't want to overwrite any pre-existing file
// so we check for Size() == 0 below (This is racy, but using O_EXCL would also be racy,
// only in a different way. Either way, it’s up to the user to not have two writers to the same path.)
fh, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
fh, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o644)
if err != nil {
return nil, fmt.Errorf("opening file %q: %w", path, err)
}
Expand Down
2 changes: 1 addition & 1 deletion docker/daemon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestTlsConfigFromCertPath(t *testing.T) {
}

func TestSkipTLSVerifyOnly(t *testing.T) {
//testDir := testDir(t)
// testDir := testDir(t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment can just be dropped.


ctx := &types.SystemContext{
DockerDaemonInsecureSkipTLSVerify: true,
Expand Down
Loading