Skip to content

Commit cbbd1df

Browse files
authored
core: Always make AppDataDir for InstanceID (#5976)
1 parent 7d919af commit cbbd1df

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

caddy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,18 @@ func ParseDuration(s string) (time.Duration, error) {
825825
// regardless of storage configuration, since each instance is intended to
826826
// have its own unique ID.
827827
func InstanceID() (uuid.UUID, error) {
828-
uuidFilePath := filepath.Join(AppDataDir(), "instance.uuid")
828+
appDataDir := AppDataDir()
829+
uuidFilePath := filepath.Join(appDataDir, "instance.uuid")
829830
uuidFileBytes, err := os.ReadFile(uuidFilePath)
830831
if os.IsNotExist(err) {
831832
uuid, err := uuid.NewRandom()
832833
if err != nil {
833834
return uuid, err
834835
}
836+
err = os.MkdirAll(appDataDir, 0o600)
837+
if err != nil {
838+
return uuid, err
839+
}
835840
err = os.WriteFile(uuidFilePath, []byte(uuid.String()), 0o600)
836841
return uuid, err
837842
} else if err != nil {

0 commit comments

Comments
 (0)