diff --git a/node.go b/node.go index 6a4f2d0..6dce2d4 100644 --- a/node.go +++ b/node.go @@ -25,6 +25,7 @@ func InitNodeUUID() (*uuid.UUID, error) { } } + slog.Debug("UUID: Reading UUID") f, err := os.Open(UUID_PATH) if err != nil { return nil, err @@ -41,23 +42,33 @@ func InitNodeUUID() (*uuid.UUID, error) { } func createNodeUUID() (*uuid.UUID, error) { - err := os.MkdirAll(CONFIG_PATH, 0755) + uuid, err := uuid.NewRandom() if err != nil { return nil, err } + err = os.MkdirAll(CONFIG_PATH, 0755) + if err != nil { + slog.Error(err.Error()) + slog.Warn("Could not create /etc/hvpn directory!") + slog.Info("Proccedig without saving node UUID") + return &uuid, nil + } + mode := os.O_RDWR | os.O_CREATE | os.O_EXCL f, err := os.OpenFile(UUID_PATH, mode, 0644) if err != nil { - return nil, err - } - uuid, err := uuid.NewRandom() - if err != nil { - return nil, err + slog.Error(err.Error()) + slog.Warn("Could not open uuid file") + slog.Info("Proccedig without saving node UUID") + return &uuid, nil } n, err := f.Write(uuid[:]) if err != nil { - return nil, err + slog.Error(err.Error()) + slog.Warn("Could not write to uuid file") + slog.Info("Proccesing without saving node UUID") + return &uuid, nil } slog.Debug("UUID: Wrote " + fmt.Sprint(n) + "bytes") return &uuid, nil