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

Commit 36d2650

Browse files
authored
Merge pull request #34 from peak-stephen/fix-file-hashing
Skip reading of non-regular files
2 parents 8f29b91 + 3220455 commit 36d2650

File tree

1 file changed

+22
-11
lines changed
  • cmd/pulumi-resource-docker-buildkit

1 file changed

+22
-11
lines changed

cmd/pulumi-resource-docker-buildkit/main.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,30 @@ func newContextHash(contextPath string) *contextHash {
397397
}
398398

399399
func (ch *contextHash) hashPath(path string, fileMode fs.FileMode) error {
400-
f, err := os.Open(filepath.Join(ch.contextPath, path))
401-
if err != nil {
402-
return fmt.Errorf("open %s: %w", path, err)
403-
}
404-
defer f.Close()
405-
h := sha256.New()
406-
_, err = io.Copy(h, f)
407-
if err != nil {
408-
return fmt.Errorf("read %s: %w", path, err)
409-
}
410400
ch.input.Write([]byte(path))
411401
ch.input.Write([]byte(fileMode.String()))
412-
ch.input.Write(h.Sum(nil))
402+
403+
fullpath := filepath.Join(ch.contextPath, path)
404+
if fileMode.IsRegular() {
405+
f, err := os.Open(fullpath)
406+
if err != nil {
407+
return fmt.Errorf("open %s: %w", path, err)
408+
}
409+
defer f.Close()
410+
h := sha256.New()
411+
_, err = io.Copy(h, f)
412+
if err != nil {
413+
return fmt.Errorf("read %s: %w", path, err)
414+
}
415+
ch.input.Write(h.Sum(nil))
416+
} else if fileMode&fs.ModeSymlink != 0 {
417+
dest, err := os.Readlink(fullpath)
418+
if err != nil {
419+
return fmt.Errorf("readlink %s:")
420+
}
421+
ch.input.Write([]byte(dest))
422+
}
423+
413424
ch.input.WriteByte(0)
414425
return nil
415426
}

0 commit comments

Comments
 (0)