aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-24 21:17:04 +0900
committerOphestra <cat@gensokyo.uk>2025-09-24 21:17:04 +0900
commit65a0bb972962121108abf10208009af859222748 (patch)
treebddbf1bf278e6ccf6eafbfe98d80a3e9c9b5580c
parentafa7a0800da2bb44fd9daaea1180c046ea111db8 (diff)
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 <cat@gensokyo.uk>
-rw-r--r--internal/sys/hsu.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/internal/sys/hsu.go b/internal/sys/hsu.go
index 39fb4f18..5ae12046 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.