Ensure data sub-directories exist

This commit is contained in:
Andrew-71 2024-05-04 22:42:47 +03:00
parent 78837baad5
commit 04a5fca443
2 changed files with 6 additions and 0 deletions

View file

@ -3,6 +3,7 @@ List of things to add to this project
* CI/CD pipeline * CI/CD pipeline
* Better docs in case others want to use ths for some reason * 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 * GitHub/Codeberg/whatever mirror for when `faye` (my server) is offline
* Check export function for improvements * Check export function for improvements
* *Go* dependency-less? <-- this is a terrible idea * *Go* dependency-less? <-- this is a terrible idea

View file

@ -41,6 +41,11 @@ func SaveFile(filename string, contents []byte) error {
"file", filename) "file", filename)
return err 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) f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil { if err != nil {
slog.Error("error opening/making file", slog.Error("error opening/making file",