From d0f0da6626c322352a5f06e55d31d6bba1a81fa0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 13 Jul 2018 09:14:59 -0700 Subject: [PATCH 1/2] allow absolute paths to isos in checksum files --- common/iso_config.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/common/iso_config.go b/common/iso_config.go index e5a1e4e90..2836cbcc9 100644 --- a/common/iso_config.go +++ b/common/iso_config.go @@ -95,7 +95,6 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [ errs = append(errs, err) return warnings, errs } - case "": break default: @@ -153,7 +152,8 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error { 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 { line, err := rd.ReadString('\n') if err != nil && line == "" { @@ -163,12 +163,14 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error { if len(parts) < 2 { continue } + options := []string{filename, relpath, "./" + relpath, u.Path} if strings.ToLower(parts[0]) == c.ISOChecksumType { // BSD-style checksum - if parts[1] == fmt.Sprintf("(%s)", filename) || parts[1] == fmt.Sprintf("(%s)", relpath) || - parts[1] == fmt.Sprintf("(./%s)", relpath) { - c.ISOChecksum = parts[3] - return nil + for _, match := range options { + if parts[1] == fmt.Sprintf("(%s)", match) { + c.ISOChecksum = parts[3] + return nil + } } } else { // Standard checksum @@ -176,9 +178,11 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error { // Binary mode parts[1] = parts[1][1:] } - if parts[1] == filename || parts[1] == relpath || parts[1] == "./"+relpath { - c.ISOChecksum = parts[0] - return nil + for _, match := range options { + if parts[1] == match { + c.ISOChecksum = parts[0] + return nil + } } } } From 0df33cd0326eb2d0930de861bc835e012627a1ee Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 13 Jul 2018 09:21:04 -0700 Subject: [PATCH 2/2] fix relative pathing versus iso checksum dir to work even if user has provided a relative path for the iso_url which is relative to the directory where Packer is run. --- common/iso_config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/iso_config.go b/common/iso_config.go index 2836cbcc9..857c13f57 100644 --- a/common/iso_config.go +++ b/common/iso_config.go @@ -145,7 +145,12 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error { return err } - relpath, err := filepath.Rel(filepath.Dir(checksumurl.Path), u.Path) + absPath, err := filepath.Abs(u.Path) + if err != nil { + return fmt.Errorf("Unable to generate absolute path from provided iso_url: %s", err) + } + + relpath, err := filepath.Rel(filepath.Dir(checksumurl.Path), absPath) if err != nil { return err } @@ -163,7 +168,7 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error { if len(parts) < 2 { continue } - options := []string{filename, relpath, "./" + relpath, u.Path} + options := []string{filename, relpath, "./" + relpath, absPath} if strings.ToLower(parts[0]) == c.ISOChecksumType { // BSD-style checksum for _, match := range options {