From 65a0bb972962121108abf10208009af859222748 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 24 Sep 2025 21:17:04 +0900 Subject: [PATCH] internal/sys/hsu: expose hsurc identifier This maintains a compatible interface for now, to ease merging of the upcoming changes to internal/app. Signed-off-by: Ophestra --- internal/sys/hsu.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/sys/hsu.go b/internal/sys/hsu.go index 39fb4f1..5ae1204 100644 --- a/internal/sys/hsu.go +++ b/internal/sys/hsu.go @@ -24,7 +24,8 @@ type Hsu struct { var ErrHsuAccess = errors.New("current user is not in the hsurc file") -func (h *Hsu) Uid(identity int) (int, error) { +// ID returns the current user hsurc identifier. ErrHsuAccess is returned if the current user is not in hsurc. +func (h *Hsu) ID() (int, error) { h.idOnce.Do(func() { h.id = -1 hsuPath := internal.MustHsuPath() @@ -54,11 +55,15 @@ func (h *Hsu) Uid(identity int) (int, error) { } }) - uid := -1 - if h.id >= 0 { - uid = 1000000 + h.id*10000 + identity + return h.id, h.idErr +} + +func (h *Hsu) Uid(identity int) (int, error) { + id, err := h.ID() + if err == nil { + return 1000000 + id*10000 + identity, nil } - return uid, h.idErr + return id, err } // MustUid calls [State.Uid] and terminates on error.