Skip to content

Commit

Permalink
fix: Fix hash calculation to not crash on missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Apr 19, 2024
1 parent 775cc83 commit 1ba1472
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions embed_util/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func CopyForEmbed(out string, dir string) error {
return err
}

return doWriteFilesList(out, fl)
return doWriteFilesList(dir, out, fl)
}

func BuildAndWriteFilesList(dir string) error {
fl, err := buildFileListFromDir(dir)
if err != nil {
return err
}
return doWriteFilesList(dir, fl)
return doWriteFilesList(dir, dir, fl)
}

func doWriteFilesList(dir string, fl *fileList) error {
func doWriteFilesList(srcDir string, outDir string, fl *fileList) error {
var err error
fl.ContentHash, err = calcContentHash(dir, fl)
fl.ContentHash, err = calcContentHash(srcDir, fl)
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func doWriteFilesList(dir string, fl *fileList) error {
return err
}

err = os.WriteFile(filepath.Join(dir, "files.json"), b, 0o644)
err = os.WriteFile(filepath.Join(outDir, "files.json"), b, 0o644)
if err != nil {
return err
}
Expand Down Expand Up @@ -175,10 +175,6 @@ func calcContentHash(dir string, fl *fileList) (string, error) {
_ = binary.Write(hash, binary.LittleEndian, fle.Name)
} else if st.Mode().IsRegular() {
outPath := filepath.Join(dir, fle.Name)
if fle.Compressed {
outPath += ".gz"
}

data, err := os.ReadFile(outPath)
if err != nil {
return "", err
Expand Down

0 comments on commit 1ba1472

Please sign in to comment.