From 8d39b9614f054e180f991d780ca3f3ef8d98f676 Mon Sep 17 00:00:00 2001 From: Up Date: Wed, 8 May 2024 11:28:41 +0200 Subject: [PATCH] prevent crash if userdata dir does not exist --- db/db.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db/db.go b/db/db.go index 05e92c4..cdf8bb4 100644 --- a/db/db.go +++ b/db/db.go @@ -50,6 +50,16 @@ func Init(username, password, protocol, address, database string) error { } // TODO temp code + _, err = os.Stat("userdata") + if err != nil { + if os.IsNotExist(err) { // not found, do not migrate + return nil + } else { + log.Fatalf("failed to stat userdata directory: %s", err) + return err + } + } + entries, err := os.ReadDir("userdata") if err != nil { log.Fatalln(err)