From 04a5fca443464a60a841b5f510da10b51ecb3ac7 Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sat, 4 May 2024 22:42:47 +0300 Subject: [PATCH] Ensure data sub-directories exist --- TODO.md | 1 + files.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/TODO.md b/TODO.md index 7d462c5..873dded 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,7 @@ List of things to add to this project * CI/CD pipeline * Better docs in case others want to use ths for some reason +* PWA support? I heard it's like installing websites as apps, could be useful! * GitHub/Codeberg/whatever mirror for when `faye` (my server) is offline * Check export function for improvements * *Go* dependency-less? <-- this is a terrible idea \ No newline at end of file diff --git a/files.go b/files.go index fa24f79..920684c 100644 --- a/files.go +++ b/files.go @@ -41,6 +41,11 @@ func SaveFile(filename string, contents []byte) error { "file", filename) return err } + err := os.MkdirAll(path.Dir(filename), 0755) // Create dir in case it doesn't exist yet to avoid errors + if err != nil { + slog.Error("error creating directory", "error", err, "file", filename) + return err + } f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { slog.Error("error opening/making file",