From b998fa9e7cf6378a5e45a58fbad37ec505159681 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Sat, 2 Nov 2019 20:18:21 -0700 Subject: [PATCH] Adds suffixing for file writes --- client.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/client.go b/client.go index 452dad1..599bade 100644 --- a/client.go +++ b/client.go @@ -529,6 +529,14 @@ func (c *client) saveFile(u Url, name string) { } savePath := filepath.Join(c.Options["savelocation"], name) + suffix := 1 + _, fileErr := os.Stat(savePath) + for fileErr == nil { + fn := fmt.Sprintf("%s.%d", name, suffix) + savePath = filepath.Join(c.Options["savelocation"], fn) + _, fileErr = os.Stat(savePath) + suffix++ + } err = ioutil.WriteFile(savePath, file, 0644) if err != nil { c.SetMessage("Error writing file: "+err.Error(), true) @@ -546,6 +554,14 @@ func (c *client) saveFileFromData(d, name string) { c.DrawMessage() savePath := filepath.Join(c.Options["savelocation"], name) + suffix := 1 + _, fileErr := os.Stat(savePath) + for fileErr == nil { + fn := fmt.Sprintf("%s.%d", name, suffix) + savePath = filepath.Join(c.Options["savelocation"], fn) + _, fileErr = os.Stat(savePath) + suffix++ + } err := ioutil.WriteFile(savePath, data, 0644) if err != nil { c.SetMessage("Error writing file: "+err.Error(), true)