Merge pull request #5578 from paboldin/do-5577
iso_config: allow for subdirs in hash sum files
This commit is contained in:
commit
2f9a6a99bd
|
@ -140,9 +140,20 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
checksumurl, err := url.Parse(c.ISOChecksumURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relpath, err := filepath.Rel(filepath.Dir(checksumurl.Path), u.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filename := filepath.Base(u.Path)
|
||||
|
||||
errNotFound := fmt.Errorf("No checksum for %q found at: %s", filename, c.ISOChecksumURL)
|
||||
errNotFound := fmt.Errorf("No checksum for %q or %q found at: %s", filename, relpath, c.ISOChecksumURL)
|
||||
for {
|
||||
line, err := rd.ReadString('\n')
|
||||
if err != nil && line == "" {
|
||||
|
@ -154,7 +165,8 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error {
|
|||
}
|
||||
if strings.ToLower(parts[0]) == c.ISOChecksumType {
|
||||
// BSD-style checksum
|
||||
if parts[1] == fmt.Sprintf("(%s)", filename) {
|
||||
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
|
||||
}
|
||||
|
@ -164,7 +176,7 @@ func (c *ISOConfig) parseCheckSumFile(rd *bufio.Reader) error {
|
|||
// Binary mode
|
||||
parts[1] = parts[1][1:]
|
||||
}
|
||||
if parts[1] == filename {
|
||||
if parts[1] == filename || parts[1] == relpath || parts[1] == "./"+relpath {
|
||||
c.ISOChecksum = parts[0]
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,11 +24,21 @@ MD5 (other.iso) = bAr
|
|||
MD5 (the-OS.iso) = baZ
|
||||
`
|
||||
|
||||
var cs_bsd_style_subdir = `
|
||||
MD5 (other.iso) = bAr
|
||||
MD5 (./subdir/the-OS.iso) = baZ
|
||||
`
|
||||
|
||||
var cs_gnu_style = `
|
||||
bAr0 *the-OS.iso
|
||||
baZ0 other.iso
|
||||
`
|
||||
|
||||
var cs_gnu_style_subdir = `
|
||||
bAr0 *./subdir/the-OS.iso
|
||||
baZ0 other.iso
|
||||
`
|
||||
|
||||
var cs_bsd_style_no_newline = `
|
||||
MD5 (other.iso) = bAr
|
||||
MD5 (the-OS.iso) = baZ`
|
||||
|
@ -134,6 +144,27 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
t.Fatalf("should've found \"baz\" got: %s", i.ISOChecksum)
|
||||
}
|
||||
|
||||
// Test good - ISOChecksumURL BSD style with relative path
|
||||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
|
||||
cs_dir, _ := ioutil.TempDir("", "packer-testdir-")
|
||||
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_bsd_style_subdir), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
|
||||
warns, err = i.Prepare(nil)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if i.ISOChecksum != "baz" {
|
||||
t.Fatalf("should've found \"baz\" got: %s", i.ISOChecksum)
|
||||
}
|
||||
|
||||
// Test good - ISOChecksumURL GNU style no newline
|
||||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
|
@ -171,6 +202,26 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
|
|||
if i.ISOChecksum != "bar0" {
|
||||
t.Fatalf("should've found \"bar0\" got: %s", i.ISOChecksum)
|
||||
}
|
||||
|
||||
// Test good - ISOChecksumURL GNU style with relative path
|
||||
i = testISOConfig()
|
||||
i.ISOChecksum = ""
|
||||
|
||||
cs_file, _ = ioutil.TempFile(cs_dir, "packer-test-")
|
||||
ioutil.WriteFile(cs_file.Name(), []byte(cs_gnu_style_subdir), 0666)
|
||||
i.ISOChecksumURL = fmt.Sprintf("%s%s", filePrefix, cs_file.Name())
|
||||
i.RawSingleISOUrl = fmt.Sprintf("%s%s", cs_dir, "/subdir/the-OS.iso")
|
||||
warns, err = i.Prepare(nil)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if i.ISOChecksum != "bar0" {
|
||||
t.Fatalf("should've found \"bar0\" got: %s", i.ISOChecksum)
|
||||
}
|
||||
}
|
||||
|
||||
func TestISOConfigPrepare_ISOChecksumType(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue