allow absolute paths to isos in checksum files

This commit is contained in:
Megan Marsh 2018-07-13 09:14:59 -07:00
parent 8e22803099
commit d0f0da6626
1 changed files with 13 additions and 9 deletions

View File

@ -95,7 +95,6 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
errs = append(errs, err) errs = append(errs, err)
return warnings, errs return warnings, errs
} }
case "": case "":
break break
default: default:
@ -153,7 +152,8 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error {
filename := filepath.Base(u.Path) filename := filepath.Base(u.Path)
errNotFound := fmt.Errorf("No checksum for %q or %q found at: %s", filename, relpath, c.ISOChecksumURL) errNotFound := fmt.Errorf("No checksum for %q, %q or %q found at: %s",
filename, relpath, u.Path, c.ISOChecksumURL)
for { for {
line, err := rd.ReadString('\n') line, err := rd.ReadString('\n')
if err != nil && line == "" { if err != nil && line == "" {
@ -163,24 +163,28 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error {
if len(parts) < 2 { if len(parts) < 2 {
continue continue
} }
options := []string{filename, relpath, "./" + relpath, u.Path}
if strings.ToLower(parts[0]) == c.ISOChecksumType { if strings.ToLower(parts[0]) == c.ISOChecksumType {
// BSD-style checksum // BSD-style checksum
if parts[1] == fmt.Sprintf("(%s)", filename) || parts[1] == fmt.Sprintf("(%s)", relpath) || for _, match := range options {
parts[1] == fmt.Sprintf("(./%s)", relpath) { if parts[1] == fmt.Sprintf("(%s)", match) {
c.ISOChecksum = parts[3] c.ISOChecksum = parts[3]
return nil return nil
} }
}
} else { } else {
// Standard checksum // Standard checksum
if parts[1][0] == '*' { if parts[1][0] == '*' {
// Binary mode // Binary mode
parts[1] = parts[1][1:] parts[1] = parts[1][1:]
} }
if parts[1] == filename || parts[1] == relpath || parts[1] == "./"+relpath { for _, match := range options {
if parts[1] == match {
c.ISOChecksum = parts[0] c.ISOChecksum = parts[0]
return nil return nil
} }
} }
} }
}
return errNotFound return errNotFound
} }