fix(auth): Improve file-based auth handling and consistency

This commit is contained in:
hkfires
2025-09-22 13:03:47 +08:00
parent 0607e52767
commit 759bb88a90
2 changed files with 16 additions and 1 deletions

View File

@@ -64,6 +64,15 @@ func (s *FileStore) Save(ctx context.Context, auth *Auth) error {
if path == "" {
return fmt.Errorf("auth filestore: missing file path attribute for %s", auth.ID)
}
// If the auth has been disabled and the original file was removed, avoid
// recreating it on disk. This lets operators delete auth files explicitly.
if auth.Disabled {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil
}
}
}
s.mu.Lock()
defer s.mu.Unlock()
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {