diff --git a/gadget/gadget.go b/gadget/gadget.go index 0347f98f5c6..202ac0215c5 100644 --- a/gadget/gadget.go +++ b/gadget/gadget.go @@ -1438,18 +1438,17 @@ func validateOffsetWrite(s, firstStruct *VolumeStructure, volSize quantity.Size) return nil } -func contentCheckerCreate(vs *VolumeStructure, vol *Volume) func(string, *VolumeContent) error { - if vol.Schema == schemaEMMC { +func contentCheckerCreate(vs *VolumeStructure, vol *Volume) func(*VolumeContent) error { + switch { + case vol.Schema == schemaEMMC: return validateEMMCContent - } - - if vs.HasFilesystem() { + case vs.HasFilesystem(): return validateFilesystemContent + default: + // default to bare content checker if no filesystem + // is present + return validateBareContent } - - // default to bare content checker if no filesystem - // is present - return validateBareContent } func validateVolumeStructure(vs *VolumeStructure, vol *Volume) error { @@ -1480,7 +1479,7 @@ func validateVolumeStructure(vs *VolumeStructure, vol *Volume) error { contentChecker := contentCheckerCreate(vs, vol) for i, c := range vs.Content { - if err := contentChecker(vs.Name, &c); err != nil { + if err := contentChecker(&c); err != nil { return fmt.Errorf("invalid content #%v: %v", i, err) } } @@ -1618,7 +1617,7 @@ func validateRole(vs *VolumeStructure) error { return nil } -func validateBareContent(_ string, vc *VolumeContent) error { +func validateBareContent(vc *VolumeContent) error { if vc.UnresolvedSource != "" || vc.Target != "" { return fmt.Errorf("cannot use non-image content for bare file system") } @@ -1628,9 +1627,9 @@ func validateBareContent(_ string, vc *VolumeContent) error { return nil } -func validateEMMCContent(name string, vc *VolumeContent) error { +func validateEMMCContent(vc *VolumeContent) error { if vc.Offset != nil || vc.Size != 0 { - return fmt.Errorf("cannot specify size or offset for content in %q", name) + return fmt.Errorf("cannot specify size or offset for content") } if vc.UnresolvedSource != "" || vc.Target != "" { @@ -1642,7 +1641,7 @@ func validateEMMCContent(name string, vc *VolumeContent) error { return nil } -func validateFilesystemContent(_ string, vc *VolumeContent) error { +func validateFilesystemContent(vc *VolumeContent) error { if vc.Image != "" || vc.Offset != nil || vc.Size != 0 { return fmt.Errorf("cannot use image content for non-bare file system") } diff --git a/gadget/gadget_emmc_test.go b/gadget/gadget_emmc_test.go index 243b586ba04..ad97fc3144d 100644 --- a/gadget/gadget_emmc_test.go +++ b/gadget/gadget_emmc_test.go @@ -173,7 +173,7 @@ volumes: c.Assert(err, IsNil) _, err = gadget.ReadInfo(s.dir, coreMod) - c.Assert(err, ErrorMatches, fmt.Sprintf(`.*cannot specify size or offset for content in %q`, t)) + c.Assert(err, ErrorMatches, `.*cannot specify size or offset for content`) } } diff --git a/gadget/validate.go b/gadget/validate.go index e923902121f..1996cc56945 100644 --- a/gadget/validate.go +++ b/gadget/validate.go @@ -174,8 +174,8 @@ func validateEMMCStructureName(vs *VolumeStructure) error { if vs.EnclosingVolume.Schema != schemaEMMC { return nil } - if !strutil.ListContains(valideMMCVolumeNames, vs.Name) { - return fmt.Errorf("cannot use %q as emmc name, only %q is allowed", vs.Name, valideMMCVolumeNames) + if !strutil.ListContains(validEMMCVolumeNames, vs.Name) { + return fmt.Errorf("cannot use %q as emmc name, only %q is allowed", vs.Name, validEMMCVolumeNames) } return nil } @@ -214,7 +214,7 @@ var ( } // valid names for volumes under an eMMC schema - valideMMCVolumeNames = []string{"boot0", "boot1"} + validEMMCVolumeNames = []string{"boot0", "boot1"} ) func validateReservedLabels(vs *VolumeStructure, reservedLabels []string) error {