Skip to content

Commit

Permalink
chore: windows compatibility due to open file failures
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow committed Apr 9, 2024
1 parent 13182bb commit 8fb320e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ TASK = $(TOOL_DIR)/task
## Bootstrapping targets #################################

$(BINNY):
@mkdir -p $(TOOL_DIR)
@# we don't have a release of binny yet, so build off of the current branch
@#curl -sSfL https://raw.githubusercontent.com/$(OWNER)/$(PROJECT)/main/install.sh | sh -s -- -b $(TOOL_DIR)
@-mkdir $(TOOL_DIR)
# we don't have a release of binny yet, so build off of the current branch
# curl -sSfL https://raw.githubusercontent.com/$(OWNER)/$(PROJECT)/main/install.sh | sh -s -- -b $(TOOL_DIR)
go build -o $(TOOL_DIR)/$(PROJECT) ./cmd/$(PROJECT)

.PHONY: task
Expand Down
20 changes: 12 additions & 8 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,9 @@ func (s *Store) AddTool(toolName string, resolvedVersion, pathOutsideRoot string
}
}

file, err := os.Open(pathOutsideRoot)
digests, err := getDigestsForFile(pathOutsideRoot)
if err != nil {
return fmt.Errorf("failed to open temp copy of binary %q: %w", pathOutsideRoot, err)
}
defer file.Close()

digests, err := getDigestsForReader(file)
if err != nil {
return nil
return err
}

sha256Hash, ok := digests[internal.SHA256Algorithm]
Expand Down Expand Up @@ -338,6 +332,16 @@ func xxh64File(path string) (string, error) {
return fmt.Sprintf("%x", hash.Sum(nil)), nil
}

func getDigestsForFile(filePath string) (map[string]string, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf("failed to open temp copy of binary %q: %w", filePath, err)
}
defer file.Close()

return getDigestsForReader(file)
}

func getDigestsForReader(r io.Reader) (map[string]string, error) {
sha256Hash := sha256.New()
xxhHash := xxhash.New64()
Expand Down
1 change: 1 addition & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func TestStore_AddTool(t *testing.T) {

createFile := func(path, contents string) {
fh, err := os.Create(path)
defer fh.Close()
require.NoError(t, err)
_, err = fh.WriteString(contents)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions tool/githubrelease/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ func (i Installer) InstallTo(version, destDir string) (string, error) {
}

func downloadAndExtractAsset(lgr logger.Logger, asset ghAsset, checksumAsset *ghAsset, destDir string) (string, error) {
assetPath := path.Join(destDir, asset.Name)
assetPath := filepath.Join(destDir, asset.Name)

checksum := asset.Checksum
if checksumAsset != nil && checksum == "" {
lgr.WithFields("asset", checksumAsset.Name).Trace("downloading checksum manifest")

checksumsPath := path.Join(destDir, checksumsFilename)
checksumsPath := filepath.Join(destDir, checksumsFilename)

if err := internal.DownloadFile(lgr, checksumAsset.URL, checksumsPath, ""); err != nil {
return "", fmt.Errorf("unable to download checksum asset %q: %w", checksumAsset.Name, err)
Expand Down

0 comments on commit 8fb320e

Please sign in to comment.