From 25edd344c861851d0ac40cfb1af76b2ec3e6f726 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 7 Feb 2026 19:36:46 -0500 Subject: [PATCH] Resolve relative ssh dir during config load on iOS --- config/load_GENERIC.go | 24 ++++++++++++++++++++++++ config/load_IOS.go | 27 +++++++++++++++++++++++++++ config/{cfg.go => write.go} | 13 ------------- go.mod | 2 +- 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 config/load_GENERIC.go create mode 100644 config/load_IOS.go rename config/{cfg.go => write.go} (81%) diff --git a/config/load_GENERIC.go b/config/load_GENERIC.go new file mode 100644 index 0000000..07d0911 --- /dev/null +++ b/config/load_GENERIC.go @@ -0,0 +1,24 @@ +//go:build !ios + +package config + +import ( + "encoding/json" + "errors" + "os" + + "github.com/rwinkhart/libmutton/global" +) + +// Load loads libmuttoncfg.json and returns the configuration. +func Load() (*CfgT, error) { + cfgBytes, err := os.ReadFile(global.CfgPath) + if err != nil { + return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error()) + } + var cfg CfgT + if err = json.Unmarshal(cfgBytes, &cfg); err != nil { + return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error()) + } + return &cfg, nil +} diff --git a/config/load_IOS.go b/config/load_IOS.go new file mode 100644 index 0000000..6c205ac --- /dev/null +++ b/config/load_IOS.go @@ -0,0 +1,27 @@ +//go:build ios + +package config + +import ( + "encoding/json" + "errors" + "os" + + "github.com/rwinkhart/libmutton/global" +) + +// Load loads libmuttoncfg.json and returns the configuration. +func Load() (*CfgT, error) { + cfgBytes, err := os.ReadFile(global.CfgPath) + if err != nil { + return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error()) + } + var cfg CfgT + if err = json.Unmarshal(cfgBytes, &cfg); err != nil { + return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error()) + } + + // iOS stores a relative path to account for the ever-changing app UUID + cfg.Libmutton.SSHKeyPath = new(global.SSHDir + *cfg.Libmutton.SSHKeyPath) + return &cfg, nil +} diff --git a/config/cfg.go b/config/write.go similarity index 81% rename from config/cfg.go rename to config/write.go index 8286d50..c42801a 100644 --- a/config/cfg.go +++ b/config/write.go @@ -24,19 +24,6 @@ type CfgT struct { ClientSpecific *map[string]any `json:"clientSpecific"` } -// Load loads libmuttoncfg.json and returns the configuration. -func Load() (*CfgT, error) { - cfgBytes, err := os.ReadFile(global.CfgPath) - if err != nil { - return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error()) - } - var cfg CfgT - if err = json.Unmarshal(cfgBytes, &cfg); err != nil { - return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error()) - } - return &cfg, nil -} - // Write writes cfg to libmuttoncfg.json. // If used in append mode, any nil values in the // input cfg will be substituted with the existing values. diff --git a/go.mod b/go.mod index 37ca880..e1799e6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rwinkhart/libmutton -go 1.25.7 +go 1.26rc3 require ( github.com/pkg/sftp v1.13.10