WIP fix possible path issues #62

Merged
asdf merged 3 commits from fix-path-issues into develop 2019-10-29 10:03:56 +00:00
2 changed files with 6 additions and 6 deletions
Showing only changes of commit be4741895e - Show all commits

View File

@ -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)
Outdated
Review

This has a slight problem. path.Base, when given something like gopher://colorfield.space/1/~sloum/ will return ~sloum. When really we want it to return an empty string so that we can enter the following if block and give a default name (gophermap). However, this is still a problem even without the terminal slash. Which is what the previous logic was based around.

We may want to remove attempts to use a default filename as it seems more complicated than initially thought to figure out when that is the appropriate action. Part of me thinks: look for a . in the last path segment. If it is there it is a file name. If it isn't then use a default. But lots of files, particularly for unix based systems do not have file extensions (since they are convention and dont mean a lot to the system like they seem to on windows).

I definitely think using path.Base is probably the way to go. We just need to make some decisions on how to handle getting filenames. I think it possible that these decisions could simplify logic in a few places, which would be nice.

This has a slight problem. `path.Base`, when given something like `gopher://colorfield.space/1/~sloum/` will return `~sloum`. When really we want it to return an empty string so that we can enter the following if block and give a default name (gophermap). However, this is still a problem even without the terminal slash. Which is what the previous logic was based around. We may want to remove attempts to use a default filename as it seems more complicated than initially thought to figure out when that is the appropriate action. Part of me thinks: look for a `.` in the last path segment. If it is there it is a file name. If it isn't then use a default. But lots of files, particularly for unix based systems do not have file extensions (since they are convention and dont mean a lot to the system like they seem to on windows). I definitely think using path.Base is probably the way to go. We just need to make some decisions on how to handle getting filenames. I think it possible that these decisions could simplify logic in a few places, which would be nice.
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 + + + \\
//--------------------------------------------------\\

View File

@ -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)
Outdated
Review

This is good 👍

This is good :thumbsup:
}
func validateOpt(opt, val string) bool {