Skip to content

Commit e6b860a

Browse files
Copilotbytemain
andauthored
Address hash module review feedback
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/2766badf-41e8-4039-b36c-df0c7668b145 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent 83da267 commit e6b860a

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

internal/plugin/luai/module/hash/hash.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,16 @@ func pushFileVerify(L *lua.LState, filepath, expected, algorithm string) int {
122122
return 1
123123
}
124124

125-
func DigestFile(filepath, algorithm string) (string, error) {
125+
func DigestFile(filepath, algorithm string) (digest string, err error) {
126126
file, err := os.Open(filepath)
127127
if err != nil {
128128
return "", err
129129
}
130-
defer file.Close()
130+
defer func() {
131+
if closeErr := file.Close(); err == nil && closeErr != nil {
132+
err = closeErr
133+
}
134+
}()
131135

132136
hasher, err := newHash(algorithm)
133137
if err != nil {

internal/plugin/luai/module/hash/hash_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
func TestHashModule(t *testing.T) {
2828
tempDir := t.TempDir()
29-
testFile := filepath.Join(tempDir, "archive.tar.gz")
29+
testFile := filepath.Join(tempDir, "sample-file.txt")
3030
if err := os.WriteFile(testFile, []byte("hello world"), 0644); err != nil {
3131
t.Fatal(err)
3232
}
@@ -87,7 +87,7 @@ func TestHashModuleErrors(t *testing.T) {
8787
`
8888

8989
tempDir := t.TempDir()
90-
testFile := filepath.Join(tempDir, "archive.tar.gz")
90+
testFile := filepath.Join(tempDir, "sample-file.txt")
9191
if err := os.WriteFile(testFile, []byte("hello world"), 0644); err != nil {
9292
t.Fatal(err)
9393
}

0 commit comments

Comments
 (0)