From cbbd1df904231de58ab6c29e681050c4709169be Mon Sep 17 00:00:00 2001 From: Aziz Rmadi <46684200+armadi1809@users.noreply.github.com> Date: Wed, 13 Dec 2023 08:39:10 -0600 Subject: [PATCH] core: Always make AppDataDir for InstanceID (#5976) --- caddy.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/caddy.go b/caddy.go index 8e7dce507..4a7bd8b6d 100644 --- a/caddy.go +++ b/caddy.go @@ -825,13 +825,18 @@ func ParseDuration(s string) (time.Duration, error) { // regardless of storage configuration, since each instance is intended to // have its own unique ID. func InstanceID() (uuid.UUID, error) { - uuidFilePath := filepath.Join(AppDataDir(), "instance.uuid") + appDataDir := AppDataDir() + uuidFilePath := filepath.Join(appDataDir, "instance.uuid") uuidFileBytes, err := os.ReadFile(uuidFilePath) if os.IsNotExist(err) { uuid, err := uuid.NewRandom() if err != nil { return uuid, err } + err = os.MkdirAll(appDataDir, 0o600) + if err != nil { + return uuid, err + } err = os.WriteFile(uuidFilePath, []byte(uuid.String()), 0o600) return uuid, err } else if err != nil {