Skip to content

Commit 6833915

Browse files
authored
fix(window): improve rename file process and remove windows release (#1728)
1 parent 019098a commit 6833915

File tree

8 files changed

+18
-72
lines changed

8 files changed

+18
-72
lines changed

.github/workflows/build-test-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
strategy:
188188
matrix:
189189
goarch: [amd64, arm64]
190-
goos: [darwin, linux, windows]
190+
goos: [darwin, linux]
191191
include:
192192
- goarch: arm
193193
goos: linux

deploy/krew/preflight.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ spec:
6060
- from: LICENSE
6161
to: .
6262
bin: preflight
63-
- selector:
64-
matchLabels:
65-
os: windows
66-
arch: amd64
67-
{{addURIAndSha "https://github.com/replicatedhq/troubleshoot/releases/download/{{ .TagName }}/preflight_windows_amd64.zip" .TagName }}
68-
files:
69-
- from: preflight.exe
70-
to: .
71-
- from: LICENSE
72-
to: .
73-
bin: preflight.exe
7463
shortDescription: Executes application preflight tests in a cluster
7564
homepage: https://github.com/replicatedhq/troubleshoot
7665
description: |

deploy/krew/support-bundle.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ spec:
6060
- from: LICENSE
6161
to: .
6262
bin: support-bundle
63-
- selector:
64-
matchLabels:
65-
os: windows
66-
arch: amd64
67-
{{addURIAndSha "https://github.com/replicatedhq/troubleshoot/releases/download/{{ .TagName }}/support-bundle_windows_amd64.zip" .TagName }}
68-
files:
69-
- from: support-bundle.exe
70-
to: .
71-
- from: LICENSE
72-
to: .
73-
bin: support-bundle.exe
7463
shortDescription: Creates support bundles for off-cluster analysis
7564
homepage: https://github.com/replicatedhq/troubleshoot
7665
description: |

internal/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func HomeDir() string {
2121
if h := os.Getenv("HOME"); h != "" {
2222
return h
2323
}
24-
return os.Getenv("USERPROFILE") // windows
24+
return ""
2525
}
2626

2727
func IsURL(str string) bool {

internal/util/util_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ func Test_HomeDir(t *testing.T) {
2121
dir: "/home/test",
2222
want: "/home/test",
2323
},
24-
{
25-
name: "test windows home directory",
26-
env: "USERPROFILE",
27-
dir: `C:\Users\test`,
28-
want: `C:\Users\test`,
29-
},
3024
}
3125

3226
for _, tt := range tests {

pkg/collect/redact.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
4040
defer func() { <-limitCh }() // free up after the function execution has run
4141

4242
var reader io.Reader
43+
var readerCloseFn func() error // Function to close reader if needed
4344
if data == nil {
4445

4546
// Collected contents are in a file. Get a reader to the file.
@@ -83,12 +84,13 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
8384
errorCh <- errors.Wrap(err, "failed to get reader")
8485
return
8586
}
86-
defer r.Close()
8787

8888
reader = r
89+
readerCloseFn = r.Close // Ensure we close the file later
8990
} else {
9091
// Collected contents are in memory. Get a reader to the memory buffer.
9192
reader = bytes.NewBuffer(data)
93+
readerCloseFn = func() error { return nil } // No-op for in-memory data
9294
}
9395

9496
// If the file is .tar, .tgz or .tar.gz, it must not be redacted. Instead it is
@@ -106,6 +108,14 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
106108
errorCh <- errors.Wrap(err, "failed to decompress file")
107109
return
108110
}
111+
112+
// Ensure the reader is closed after processing
113+
if err := readerCloseFn(); err != nil {
114+
klog.Warningf("Failed to close reader for %s: %v", file, err)
115+
errorCh <- errors.Wrap(err, "failed to close reader")
116+
return
117+
}
118+
109119
err = RedactResult(tmpDir, subResult, additionalRedactors)
110120
if err != nil {
111121
errorCh <- errors.Wrap(err, "failed to redact file")

pkg/collect/result.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,21 @@ func (r CollectorResult) ReplaceResult(bundlePath string, relativePath string, r
188188
return nil
189189
}
190190

191+
// Create a temporary file in the same directory as the target file to prevent cross-device issues
191192
tmpFile, err := os.CreateTemp("", "replace-")
192193
if err != nil {
193194
return errors.Wrap(err, "failed to create temp file")
194195
}
195-
defer tmpFile.Close()
196196

197+
// Write data to the temporary file
197198
_, err = io.Copy(tmpFile, reader)
198199
if err != nil {
199200
return errors.Wrap(err, "failed to write tmp file")
200201
}
201202

203+
// Close the file to ensure all data is written
204+
tmpFile.Close()
205+
202206
// This rename should always be in /tmp, so no cross-partition copying will happen
203207
err = os.Rename(tmpFile.Name(), filepath.Join(bundlePath, relativePath))
204208
if err != nil {

pkg/longhorn/util/iscsi_windows.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)