From be4741895e1c7ae00eec325ba803286a1544ff94 Mon Sep 17 00:00:00 2001 From: asdf Date: Sun, 27 Oct 2019 23:24:52 +1100 Subject: [PATCH] Found and addressed some possible path issues --- client.go | 9 ++++----- main.go | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 71b998d..021267a 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "os/exec" + "path" "path/filepath" "regexp" "strconv" @@ -504,6 +505,7 @@ func (c *client) getCurrentPageRawData() (string, error) { return c.PageState.History[c.PageState.Position].RawContent, nil } +// Saves the specified URL to the specified file path. func (c *client) saveFile(u Url, name string) { var file []byte var err error @@ -849,8 +851,7 @@ func (c *client) Visit(url string) { switch u.Scheme { case "gopher": if u.DownloadOnly { - nameSplit := strings.Split(u.Resource, "/") - filename := nameSplit[len(nameSplit)-1] + filename := path.Base(u.Resource) filename = strings.Trim(filename, " \t\r\n\v\f\a") if filename == "" { filename = "gopherfile" @@ -943,8 +944,7 @@ func (c *client) Visit(url string) { c.DrawMessage() c.Draw() case 'w': - nameSplit := strings.Split(u.Resource, "/") - filename := nameSplit[len(nameSplit)-1] + filename := path.Base(u.Resource) c.saveFileFromData(capsule.Content, filename) } } @@ -1035,7 +1035,6 @@ func (c *client) ReloadPage() error { return nil } - //------------------------------------------------\\ // + + + F U N C T I O N S + + + \\ //--------------------------------------------------\\ diff --git a/main.go b/main.go index 8a95281..867ef17 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ import ( "io/ioutil" "os" "os/signal" + "path/filepath" "strings" "syscall" @@ -61,7 +62,7 @@ func saveConfig() error { opts.WriteString(certs) - return ioutil.WriteFile(bombadillo.Options["configlocation"]+"/.bombadillo.ini", []byte(opts.String()), 0644) + return ioutil.WriteFile(filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini"), []byte(opts.String()), 0644) } func validateOpt(opt, val string) bool {