Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(window): improve rename file process and remove windows release #1728

Merged
merged 18 commits into from
Feb 11, 2025
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ jobs:
strategy:
matrix:
goarch: [amd64, arm64]
goos: [darwin, linux, windows]
goos: [darwin, linux]
include:
- goarch: arm
goos: linux
Expand Down
11 changes: 0 additions & 11 deletions deploy/krew/preflight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ spec:
- from: LICENSE
to: .
bin: preflight
- selector:
matchLabels:
os: windows
arch: amd64
{{addURIAndSha "https://github.com/replicatedhq/troubleshoot/releases/download/{{ .TagName }}/preflight_windows_amd64.zip" .TagName }}
files:
- from: preflight.exe
to: .
- from: LICENSE
to: .
bin: preflight.exe
shortDescription: Executes application preflight tests in a cluster
homepage: https://github.com/replicatedhq/troubleshoot
description: |
Expand Down
11 changes: 0 additions & 11 deletions deploy/krew/support-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ spec:
- from: LICENSE
to: .
bin: support-bundle
- selector:
matchLabels:
os: windows
arch: amd64
{{addURIAndSha "https://github.com/replicatedhq/troubleshoot/releases/download/{{ .TagName }}/support-bundle_windows_amd64.zip" .TagName }}
files:
- from: support-bundle.exe
to: .
- from: LICENSE
to: .
bin: support-bundle.exe
shortDescription: Creates support bundles for off-cluster analysis
homepage: https://github.com/replicatedhq/troubleshoot
description: |
Expand Down
2 changes: 1 addition & 1 deletion internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func HomeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
return os.Getenv("USERPROFILE") // windows
return ""
}

func IsURL(str string) bool {
Expand Down
6 changes: 0 additions & 6 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ func Test_HomeDir(t *testing.T) {
dir: "/home/test",
want: "/home/test",
},
{
name: "test windows home directory",
env: "USERPROFILE",
dir: `C:\Users\test`,
want: `C:\Users\test`,
},
}

for _, tt := range tests {
Expand Down
12 changes: 11 additions & 1 deletion pkg/collect/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
defer func() { <-limitCh }() // free up after the function execution has run

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

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

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

// If the file is .tar, .tgz or .tar.gz, it must not be redacted. Instead it is
Expand All @@ -106,6 +108,14 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
errorCh <- errors.Wrap(err, "failed to decompress file")
return
}

// Ensure the reader is closed after processing
if err := readerCloseFn(); err != nil {
klog.Warningf("Failed to close reader for %s: %v", file, err)
errorCh <- errors.Wrap(err, "failed to close reader")
return
}

err = RedactResult(tmpDir, subResult, additionalRedactors)
if err != nil {
errorCh <- errors.Wrap(err, "failed to redact file")
Expand Down
6 changes: 5 additions & 1 deletion pkg/collect/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,21 @@ func (r CollectorResult) ReplaceResult(bundlePath string, relativePath string, r
return nil
}

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

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

// Close the file to ensure all data is written
tmpFile.Close()

// This rename should always be in /tmp, so no cross-partition copying will happen
err = os.Rename(tmpFile.Name(), filepath.Join(bundlePath, relativePath))
if err != nil {
Expand Down
40 changes: 0 additions & 40 deletions pkg/longhorn/util/iscsi_windows.go

This file was deleted.

Loading