From cf4ff0245f4fdc62b46cccca0b983a4f2e0e7895 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 23 Mar 2024 18:00:57 +0100 Subject: [PATCH] admin: When generating team's symlinks, remove existing ones --- admin/api/password.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/admin/api/password.go b/admin/api/password.go index 2c26cd9d..a626ee22 100644 --- a/admin/api/password.go +++ b/admin/api/password.go @@ -215,6 +215,12 @@ func genDexConfig() ([]byte, error) { } else { // Also generate team associations for _, team := range teams { + if _, err := os.Stat(path.Join(TeamsDir, fmt.Sprintf("team%02d", team.Id))); err == nil { + if err = os.Remove(path.Join(TeamsDir, fmt.Sprintf("team%02d", team.Id))); err != nil { + log.Println("Unable to remove existing association symlink:", err.Error()) + return nil, fmt.Errorf("Unable to remove existing association symlink: %s", err.Error()) + } + } if err := os.Symlink(fmt.Sprintf("%d", team.Id), path.Join(TeamsDir, fmt.Sprintf("team%02d", team.Id))); err != nil { log.Println("Unable to create association symlink:", err.Error()) return nil, fmt.Errorf("Unable to create association symlink: %s", err.Error())