fixed not being able to resolve homedir key path

This commit is contained in:
partisan 2025-01-18 17:03:14 +01:00
parent c4693c4b14
commit 3bbc65268d
4 changed files with 15 additions and 5 deletions

View file

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