Fix write files error #47 #50
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#50
Loading…
Reference in New Issue
No description provided.
Delete Branch "asdf/bombadillo:fix-write-files"
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 is a fix for #47.
File paths are being constructed by concatenating strings, and was missing a forward slash.
This was a really good find! Exposes I bug I wouldnt have thought of. I left a note for futher action.
@ -507,3 +504,3 @@
return
}
savePath := c.Options["savelocation"] + name
savePath := c.Options["savelocation"] + "/" + name
This is a good find, however, I think we'll need to check for the presence of a terminal slash on savelocation. I have one, so saving was working for me (which is why this was a surprise). So I think doing:
There may be a more elegant way to go about it. I think there is a
strings.HasSuffix
function that might be easier.The path/filepath library has a Join function to construct a path in each of the cases suggested. It is also compatible with multiple operating systems, so it should work on Windows too.
What do you think of this approach?
Also it seems the same issue exists in function
saveFileFromData
Awesome! Really good find. Lets go with that. It checks off a lot of good boxes: standard library, few to no edge cases, cross platform.
Can you add it in both places? If you dont have time I can pull this branch and do so, just let me know.
saveFile and saveFileFromData now use
path/filepath
to join savelocation and filename.I've tested and can download gopher and gemini documents. I'm not sure how saveFileFromData is called exactly, so haven't tested that.
One thing I noticed during this fix is there are other path operations like:
nameSplit := strings.Split(u.Resource, "/")
filename := nameSplit[len(nameSplit)-1]
path/filepath
handles files paths on multiple operating systems, and thepath
library focuses on forward-slash only paths like URLs. It has functions like Base to return the last element of a path, which could replace the above with:filename := path.Base(u.Resource)
If you are interested in making this change, let me know.
Yes. I think it would be good to replace my hacked together versions of these things with cross-platform support by the standard library where possible. I think this PR solves the issue as presented for writing files so I will merge this in and open an issue for combing through the codebase and making adjustments to path oriented operations.