Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from peak-stephen/fix-file-hashing
Browse files Browse the repository at this point in the history
Skip reading of non-regular files
  • Loading branch information
benesch authored Jan 29, 2023
2 parents 8f29b91 + 3220455 commit 36d2650
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions cmd/pulumi-resource-docker-buildkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,30 @@ func newContextHash(contextPath string) *contextHash {
}

func (ch *contextHash) hashPath(path string, fileMode fs.FileMode) error {
f, err := os.Open(filepath.Join(ch.contextPath, path))
if err != nil {
return fmt.Errorf("open %s: %w", path, err)
}
defer f.Close()
h := sha256.New()
_, err = io.Copy(h, f)
if err != nil {
return fmt.Errorf("read %s: %w", path, err)
}
ch.input.Write([]byte(path))
ch.input.Write([]byte(fileMode.String()))
ch.input.Write(h.Sum(nil))

fullpath := filepath.Join(ch.contextPath, path)
if fileMode.IsRegular() {
f, err := os.Open(fullpath)
if err != nil {
return fmt.Errorf("open %s: %w", path, err)
}
defer f.Close()
h := sha256.New()
_, err = io.Copy(h, f)
if err != nil {
return fmt.Errorf("read %s: %w", path, err)
}
ch.input.Write(h.Sum(nil))
} else if fileMode&fs.ModeSymlink != 0 {
dest, err := os.Readlink(fullpath)
if err != nil {
return fmt.Errorf("readlink %s:")
}
ch.input.Write([]byte(dest))
}

ch.input.WriteByte(0)
return nil
}
Expand Down

0 comments on commit 36d2650

Please sign in to comment.