Skip to content

Commit

Permalink
gadget: remove the name of the VS again, it was actually printed, mak…
Browse files Browse the repository at this point in the history
…ing the error message just repeating twice. rename the validEMMCNames back again to be consistent
  • Loading branch information
Meulengracht committed Nov 8, 2024
1 parent 987408f commit 5b10081
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
27 changes: 13 additions & 14 deletions gadget/gadget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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 != "" {
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion gadget/gadget_emmc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
}

Expand Down
6 changes: 3 additions & 3 deletions gadget/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5b10081

Please sign in to comment.