From 5ecf33a5307fcf4bcbbbc13939273438380a8ef8 Mon Sep 17 00:00:00 2001 From: tangyoupeng Date: Fri, 29 Dec 2023 11:54:16 +0800 Subject: [PATCH] sdk/java: fix guid update (#4299) --- sdk/java/libjfs/guid.go | 52 +++++++++++++++++++++++++---------------- sdk/java/libjfs/main.go | 5 ++++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/sdk/java/libjfs/guid.go b/sdk/java/libjfs/guid.go index 761afd7ea20a..db14d349879e 100644 --- a/sdk/java/libjfs/guid.go +++ b/sdk/java/libjfs/guid.go @@ -87,8 +87,8 @@ func (m *mapping) lookupUser(name string) uint32 { id = m.genGuid(name) } } - m.usernames[name] = id - m.userIDs[id] = name + logger.Debugf("update user to %s:%d by lookup user", name, id) + m.updateUser(name, id) return id } @@ -113,8 +113,8 @@ func (m *mapping) lookupGroup(name string) uint32 { id = uint32(id_) } } - m.groups[name] = id - m.groupIDs[id] = name + logger.Debugf("update group to %s:%d by lookup group", name, id) + m.updateGroup(name, id) return 0 } @@ -135,8 +135,8 @@ func (m *mapping) lookupUserID(id uint32) string { if len(name) > 49 { name = name[:49] } - m.usernames[name] = id - m.userIDs[id] = name + logger.Debugf("update user to %s:%d by lookup user id", name, id) + m.updateUser(name, id) return name } @@ -157,8 +157,8 @@ func (m *mapping) lookupGroupID(id uint32) string { if len(name) > 49 { name = name[:49] } - m.groups[name] = id - m.groupIDs[id] = name + logger.Debugf("update group to %s:%d by lookup group id", name, id) + m.updateGroup(name, id) return name } @@ -167,19 +167,31 @@ func (m *mapping) update(uids []pwent, gids []pwent, local bool) { defer m.Unlock() m.local = local for _, u := range uids { - oldId := m.usernames[u.name] - oldName := m.userIDs[u.id] - delete(m.userIDs, oldId) - delete(m.usernames, oldName) - m.usernames[u.name] = u.id - m.userIDs[u.id] = u.name + m.updateUser(u.name, u.id) } for _, g := range gids { - oldId := m.groups[g.name] - oldName := m.groupIDs[g.id] - delete(m.groupIDs, oldId) - delete(m.groups, oldName) - m.groups[g.name] = g.id - m.groupIDs[g.id] = g.name + m.updateGroup(g.name, g.id) } + logger.Debugf("users:\n%+v", m.usernames) + logger.Debugf("userids:\n%+v", m.userIDs) + logger.Debugf("groups:\n%+v", m.groups) + logger.Debugf("gorupids:\n%+v", m.groupIDs) +} + +func (m *mapping) updateUser(name string, id uint32) { + oldId := m.usernames[name] + oldName := m.userIDs[id] + delete(m.userIDs, oldId) + delete(m.usernames, oldName) + m.usernames[name] = id + m.userIDs[id] = name +} + +func (m *mapping) updateGroup(name string, id uint32) { + oldId := m.groups[name] + oldName := m.groupIDs[id] + delete(m.groupIDs, oldId) + delete(m.groups, oldName) + m.groups[name] = id + m.groupIDs[id] = name } diff --git a/sdk/java/libjfs/main.go b/sdk/java/libjfs/main.go index 830ed20fc3ee..f3b93cbede82 100644 --- a/sdk/java/libjfs/main.go +++ b/sdk/java/libjfs/main.go @@ -627,6 +627,11 @@ func jfs_update_uid_grouping(h uintptr, uidstr *C.char, grouping *C.char) { } } logger.Debugf("Update groups of %s to %s", w.user, strings.Join(groups, ",")) + var buffer bytes.Buffer + for _, g := range gids { + buffer.WriteString(fmt.Sprintf("\t%v:%v\n", g.name, g.id)) + } + logger.Debugf("Update gids mapping\n %s", buffer.String()) } w.m.update(uids, gids, false)