Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fix dark mode toggle wiping API tokens (related to #685)

rcourtman5d99fc2f2d2e
diff --git a/internal/config/persistence.go b/internal/config/persistence.go
index 5328122162..10808031e1 100644
--- a/internal/config/persistence.go
+++ b/internal/config/persistence.go
@@ -1342,6 +1342,12 @@ func (c *ConfigPersistence) updateEnvFile(envFile string, settings SystemSetting
return nil
}
+ // Read the existing .env file content
+ existingContent, err := os.ReadFile(envFile)
+ if err != nil {
+ return err
+ }
+
// Read the existing .env file
file, err := os.Open(envFile)
if err != nil {
@@ -1377,12 +1383,20 @@ func (c *ConfigPersistence) updateEnvFile(envFile string, settings SystemSetting
// Note: POLLING_INTERVAL is deprecated and no longer written
- // Write the updated content back atomically
+ // Build the new content
content := strings.Join(lines, "\n")
if len(lines) > 0 && !strings.HasSuffix(content, "\n") {
content += "\n"
}
+ // Only write if content actually changed
+ // This prevents unnecessary .env rewrites that trigger the config watcher,
+ // which can cause API tokens to be overwritten (related to #685)
+ if string(existingContent) == content {
+ log.Debug().Str("file", envFile).Msg("Skipping .env update - content unchanged")
+ return nil
+ }
+
// Write to temp file first
tempFile := envFile + ".tmp"
if err := os.WriteFile(tempFile, []byte(content), 0644); err != nil {