Skip to content

Commit 0782305

Browse files
committed
Add Windows-only bundle extraction temp directory fix
- Windows: Use working directory for bundle extraction temp files - Linux/macOS: Preserve original system temp behavior exactly - Prevents antivirus file locking during bundle processing on Windows - Zero impact on Linux/macOS functionality Complete Windows-only solution for GitHub issue #1607
1 parent 3342ef8 commit 0782305

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

pkg/analyze/download.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/fs"
99
"os"
1010
"path/filepath"
11+
"runtime"
1112

1213
getter "github.com/hashicorp/go-getter"
1314
"github.com/pkg/errors"
@@ -91,7 +92,21 @@ func DownloadAndAnalyze(bundleURL string, analyzersSpec string) ([]*AnalyzeResul
9192
}
9293

9394
func DownloadAndExtractSupportBundle(bundleURL string) (string, string, error) {
94-
tmpDir, err := os.MkdirTemp("", "troubleshoot-k8s")
95+
// Windows-only: Use working directory to avoid antivirus file locking
96+
// Linux/macOS: Use system temp (original behavior)
97+
var tempDir string
98+
if runtime.GOOS == "windows" {
99+
cwd, err := os.Getwd()
100+
if err != nil {
101+
tempDir = "" // Fallback to system temp
102+
} else {
103+
tempDir = cwd
104+
}
105+
} else {
106+
tempDir = "" // Linux/macOS: system temp (unchanged)
107+
}
108+
109+
tmpDir, err := os.MkdirTemp(tempDir, "troubleshoot-k8s-")
95110
if err != nil {
96111
return "", "", errors.Wrap(err, "failed to create temp dir")
97112
}
@@ -132,7 +147,16 @@ func downloadTroubleshootBundle(bundleURL string, destDir string) error {
132147
return errors.Wrap(err, "failed to get workdir")
133148
}
134149

135-
tmpDir, err := os.MkdirTemp("", "troubleshoot")
150+
// Windows-only: Use working directory to avoid antivirus file locking
151+
// Linux/macOS: Use system temp (original behavior)
152+
var tempDir string
153+
if runtime.GOOS == "windows" {
154+
tempDir = pwd // Use working directory for Windows
155+
} else {
156+
tempDir = "" // Linux/macOS: system temp (unchanged)
157+
}
158+
159+
tmpDir, err := os.MkdirTemp(tempDir, "troubleshoot-")
136160
if err != nil {
137161
return errors.Wrap(err, "failed to create tmp dir")
138162
}

0 commit comments

Comments
 (0)