Skip to content

Commit 21dc4e9

Browse files
authored
Fix ollama windows installer (#1894)
* Fix Windows filename issue in scheduled support bundles * Fix: Close temp file before executing Ollama installer on Windows Windows requires files to be closed before they can be executed. This fix ensures the temporary installer file is properly closed before attempting to run it, preventing file access errors on Windows systems.
1 parent 5aa088b commit 21dc4e9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/analyze/ollama_helper.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (h *OllamaHelper) downloadAndInstallWindows() error {
146146
return errors.Wrap(err, "failed to create temporary file")
147147
}
148148
defer os.Remove(tmpFile.Name())
149-
defer tmpFile.Close()
149+
defer tmpFile.Close() // Ensures file is closed in error paths
150150

151151
// Download installer
152152
resp, err := http.Get(h.downloadURL)
@@ -165,6 +165,13 @@ func (h *OllamaHelper) downloadAndInstallWindows() error {
165165
return errors.Wrap(err, "failed to write installer")
166166
}
167167

168+
// Close the file before executing it (required on Windows)
169+
// Note: This will be called twice (here and via defer), but that's safe
170+
// The defer ensures cleanup on error paths, this ensures closure before execution
171+
if err := tmpFile.Close(); err != nil {
172+
return errors.Wrap(err, "failed to close installer file")
173+
}
174+
168175
// Run installer
169176
klog.Info("Running Ollama installer...")
170177
cmd := exec.Command(tmpFile.Name())

0 commit comments

Comments
 (0)