Skip to content

Commit

Permalink
core: Always make AppDataDir for InstanceID (#5976)
Browse files Browse the repository at this point in the history
  • Loading branch information
armadi1809 committed Dec 13, 2023
1 parent 7d919af commit cbbd1df
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cbbd1df

Please sign in to comment.