WIP fix possible path issues #62
No reviewers
Labels
No Label
blocked
bug
build
documentation
duplicate
enhancement
finger
gemini
gopher
help wanted
http
in progress
invalid
local
needs-info
non-code
non-functional
non-urgent
question
release
rendering
suggestion
telnet
terminal
urgent
wontfix
No Milestone
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sloum/bombadillo#62
Loading…
Reference in New Issue
No description provided.
Delete Branch "fix-path-issues"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR is intended to fix #52. It's a work in progress while checking.
This will be dependent on #60, and will need to be rebased once it is merged(??? - still trying to understand how different branches work together).
There are two examples of things I've found that can be addressed:
filepath.Join()
to build the file path.path.Base
.There are a few operations with variations on the following:
Could some of these become a new function?
@ -851,3 +853,2 @@
if u.DownloadOnly {
nameSplit := strings.Split(u.Resource, "/")
filename := nameSplit[len(nameSplit)-1]
filename := path.Base(u.Resource)
This has a slight problem.
path.Base
, when given something likegopher://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.
@ -62,3 +63,3 @@
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)
This is good 👍
I've merged this with the new changes from develop and reverted the changes to client.go
I didn't see the issue with file names you had identified, and thought it was less complicated and might save some space.
We could take a look at how the file name is determined, but I'm not sure it will add much value. Even in the example you gave, ~sloum seems acceptable.
All paths used by
ioutil.WriteFile
are now created usingfilepath.Join
. It also seems any errors arising (like if the directory doesn't exist, or a write error) will be displayed to the user.Not sure there is much more to this one.
Ok. You are probably right that
~sloum
would be fine. Is~
an allowable file character on all of our target systems? Are there other characters that could be in a filename that are not valid? Should we url encode the filename just to be safe? What happens (I can test this in a bit when I get to work) if the file is the root of a directory? Will it save as hostname or as empty sting or as slash?Any file errors should occur within
ioutil.WriteFile
, and the client handles these nicely by aborting the write and printing the actual file error message so the user can interpret it.With that said, we should avoid situations where the client suggests a file name that will cause an error. This can caused by:
The existing approach might be OK, with an expansion of
strings.Trim(filename, " vfa")
to also include characters not supported by the current operating system. We can improve file naming though, but we should think about some good inputs and expected output like:(I guess I am just suggesting TDD, I'm just not sure how else to be reasonably sure that it works as we expect)
Also, I just noticed that we are not handling overwrites. If a file exists and is writable, and the same name is used, it is overwritten without warning.
Yeah. File overwrites are something I had been planning on fixing at some point and had never gotten around to (for my use case using Bombadillo I almost never save files, so when it was jsut a browser for me to use it wasnt high on the priority list). It would be nice to have.
I agree, tests to cover the various naming cases and url possibilities would be good.
this has some good discussion of character usage in filenames. Apparently anything but
/
is valid...sort of. But there are lots of good reasons to not allow a good many other characters.Also, I just noticed: this PR doesn't seem to include adjustments to writing to files. Did things get reverted?
I reverted the changes that used
path.Base()
because of the issues you pointed out. Another change was not required once mailcap was removed. Usingfilepath.Join()
when saving the configuration file is the only other item I've found requiring attention.Ok. I definitely think the
join
usage for the config works great. Do you think we should try to make file save adjustments as a part of this PR? Or merge this in?I'll merge this in. It would be good to think about other changes a bit more, but I'll raise an issue for now.