From 3bbc65268d30ee225daaf2e6d20e973eb5cb6a9a Mon Sep 17 00:00:00 2001 From: partisan Date: Sat, 18 Jan 2025 17:03:14 +0100 Subject: [PATCH] fixed not being able to resolve homedir key path --- go.mod | 2 ++ go.sum | 2 ++ main.go | 4 ++-- spitfire/upload.go | 12 +++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index c1d81fb..7c487d5 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module spitfire-builder go 1.18 + +require github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ae38d14 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= diff --git a/main.go b/main.go index fed7d4e..8d01333 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func init() { func printHelp() { fmt.Println("Usage: go run . -p= -t= [-c|--compress] [-v|--version=] [-component=] [-arch=] [-release=] [-platform=]") flag.PrintDefaults() - fmt.Println("Example: go run . --upload -c --upload-path=./mozilla-release/obj-x86_64-pc-linux-gnu/dist/bin -a") + fmt.Println("Example: go run . --upload -c -a") os.Exit(0) } @@ -277,7 +277,7 @@ func PackageAndUploadProcess(buildDir string) { fmt.Printf("Compression efficiency: %.2f%%\n", efficiency) // Display compressed directory path - fmt.Printf("Compressed dir: %s", pathToUse) + fmt.Printf("Compressed dir: %s\n", pathToUse) // If not uploading, we're done if !upload { diff --git a/spitfire/upload.go b/spitfire/upload.go index d16cc32..a0783c5 100644 --- a/spitfire/upload.go +++ b/spitfire/upload.go @@ -12,6 +12,8 @@ import ( "os/exec" "path/filepath" "strings" + + "github.com/mitchellh/go-homedir" ) // Config struct to hold SourceForge configurations @@ -24,7 +26,7 @@ type Config struct { // Load the SourceForge configuration from a file func LoadConfig() (*Config, error) { - file, err := os.Open("sourceforge_config.json") // Assuming a JSON config file + file, err := os.Open("sourceforge_config.json") if err != nil { return nil, fmt.Errorf("failed to open config file: %v", err) } @@ -35,8 +37,12 @@ func LoadConfig() (*Config, error) { return nil, fmt.Errorf("failed to decode config file: %v", err) } - // Normalize the SSH key path for the current OS - config.SFKeyPath = filepath.Clean(config.SFKeyPath) + // Expand tilde manually + expandedPath, err := homedir.Expand(config.SFKeyPath) + if err != nil { + return nil, fmt.Errorf("failed expanding key path: %v", err) + } + config.SFKeyPath = filepath.Clean(expandedPath) // Validate that the key file exists if _, err := os.Stat(config.SFKeyPath); os.IsNotExist(err) {