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

This commit is contained in:
Dexter Yan
2025-02-11 17:33:08 +13:00
committed by GitHub
parent 019098a113
commit 683391522e
8 changed files with 18 additions and 72 deletions

View File

@@ -187,7 +187,7 @@ jobs:
strategy:
matrix:
goarch: [amd64, arm64]
goos: [darwin, linux, windows]
goos: [darwin, linux]
include:
- goarch: arm
goos: linux

View File

@@ -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: |

View File

@@ -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: |

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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.
@@ -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
@@ -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")

View File

@@ -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 {

View File

@@ -1,40 +0,0 @@
//go:build windows
// +build windows
package util
import (
"github.com/pkg/errors"
)
func GetDiskInfo(directory string) (*DiskInfo, error) {
return nil, errors.Errorf("cannot get disk info of directory %v", directory)
}
func RemoveHostDirectoryContent(directory string) error {
return errors.Errorf("failed to remove host directory %v", directory)
}
func CopyHostDirectoryContent(src, dest string) error {
return errors.Errorf("failed to copy the content from %v to %v for the host", src, dest)
}
func CreateDiskPathReplicaSubdirectory(path string) error {
return errors.Errorf("error creating data path %v on host", path)
}
func ExpandFileSystem(volumeName string) error {
return errors.Errorf("error expanding filsystem on %v", volumeName)
}
func DetectFileSystem(volumeName string) (string, error) {
return "", errors.Errorf("error detecting filsystem on %v", volumeName)
}
func GetDiskConfig(path string) (*DiskConfig, error) {
return nil, errors.Errorf("error getting disk config from %v", path)
}
func GenerateDiskConfig(path string) (*DiskConfig, error) {
return nil, errors.Errorf("error generating disk config from %v", path)
}