commit 44fbef30b39bcde3cd159c4261c9a0dd86c0c667 parent ffa79f926fad25550933c9e9de6339941ec51594 Author: Sean Enck <sean@ttypty.com> Date: Thu, 18 Aug 2022 18:33:44 -0400 NewFile should not return an extension if given Diffstat:
| M | internal/store/filesystem.go | | | 5 | ++++- |
| M | internal/store/filesystem_test.go | | | 4 | ++++ |
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/internal/store/filesystem.go b/internal/store/filesystem.go @@ -81,7 +81,10 @@ func (s FileSystem) NewPath(file string) string { // NewFile creates a new file with the proper extension. func (s FileSystem) NewFile(file string) string { - return file + extension + if !strings.HasSuffix(file, extension) { + return file + extension + } + return file } // CleanPath will clean store and extension information from an entry. diff --git a/internal/store/filesystem_test.go b/internal/store/filesystem_test.go @@ -110,4 +110,8 @@ func TestNewFile(t *testing.T) { if f != "xyz.lb" { t.Error("invalid file") } + f = FileSystem{path: "abc"}.NewFile("xyz.lb") + if f != "xyz.lb" { + t.Error("invalid file, had suffix") + } }