fix(cef): use XDG data dir for user data
- commit
- d7aff0cc26bf482030f7e1875956334fce1a1182
- author
- brice · · 2026-04-14 08:41 UTC
- parent
- 371af32
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +11 -9
M internal/infrastructure/cef/engine_init.go +7 -7
| @@ -144,16 +144,16 @@ func prepareCEFSettings(opts port.EngineOptions, cfg RuntimeConfig, logger *zero | |||
| 144 | 144 | } | |
| 145 | 145 | ||
| 146 | 146 | func defaultCEFUserDataDir() string { | |
| 147 | - | // Use Dumber's XDG helpers to get the config directory | |
| 147 | + | // Keep CEF state under Dumber's XDG data directory like the rest of runtime data. | |
| 148 | 148 | dirs, err := config.GetXDGDirs() | |
| 149 | 149 | if err != nil { | |
| 150 | - | // Fallback to HOME-based path if XDG resolution fails | |
| 151 | - | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | |
| 152 | - | } | |
| 153 | - | if os.Getenv("ENV") == "dev" { | |
| 154 | - | return filepath.Join(dirs.ConfigHome, "cef_user_data") | |
| 150 | + | dataHome := os.Getenv("XDG_DATA_HOME") | |
| 151 | + | if dataHome == "" { | |
| 152 | + | dataHome = filepath.Join(os.Getenv("HOME"), ".local", "share") | |
| 153 | + | } | |
| 154 | + | return filepath.Clean(filepath.Join(dataHome, "dumber", "cef_user_data")) | |
| 155 | 155 | } | |
| 156 | - | return filepath.Join(filepath.Dir(dirs.ConfigHome), "cef_user_data") | |
| 156 | + | return filepath.Join(dirs.DataHome, "cef_user_data") | |
| 157 | 157 | } | |
| 158 | 158 | ||
| 159 | 159 | // initializeCEF calls cef_initialize with the App to register custom schemes | |
| @@ -144,16 +144,16 @@ func prepareCEFSettings(opts port.EngineOptions, cfg RuntimeConfig, logger *zero | |||||
| 144 | } | 144 | } | ||
| 145 | 145 | ||||
| 146 | func defaultCEFUserDataDir() string { | 146 | func defaultCEFUserDataDir() string { | ||
| 147 | - | // Use Dumber's XDG helpers to get the config directory | 147 | + | // Keep CEF state under Dumber's XDG data directory like the rest of runtime data. |
| 148 | dirs, err := config.GetXDGDirs() | 148 | dirs, err := config.GetXDGDirs() | ||
| 149 | if err != nil { | 149 | if err != nil { | ||
| 150 | - | // Fallback to HOME-based path if XDG resolution fails | 150 | + | dataHome := os.Getenv("XDG_DATA_HOME") |
| 151 | - | return filepath.Clean(filepath.Join(os.Getenv("HOME"), ".config", "cef_user_data")) | 151 | + | if dataHome == "" { |
| 152 | - | } | 152 | + | dataHome = filepath.Join(os.Getenv("HOME"), ".local", "share") |
| 153 | - | if os.Getenv("ENV") == "dev" { | 153 | + | } |
| 154 | - | return filepath.Join(dirs.ConfigHome, "cef_user_data") | 154 | + | return filepath.Clean(filepath.Join(dataHome, "dumber", "cef_user_data")) |
| 155 | } | 155 | } | ||
| 156 | - | return filepath.Join(filepath.Dir(dirs.ConfigHome), "cef_user_data") | 156 | + | return filepath.Join(dirs.DataHome, "cef_user_data") |
| 157 | } | 157 | } | ||
| 158 | 158 | ||||
| 159 | // initializeCEF calls cef_initialize with the App to register custom schemes | 159 | // initializeCEF calls cef_initialize with the App to register custom schemes | ||
M internal/infrastructure/cef/engine_init_test.go +4 -2
| @@ -61,16 +61,18 @@ func TestPrepareCEFInitTraceFile_EnabledViaEnv(t *testing.T) { | |||
| 61 | 61 | require.FileExists(t, path) | |
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | - | func TestPrepareCEFSettings_RootCachePath_UsesLegacyCEFUserDataDir(t *testing.T) { | |
| 64 | + | func TestPrepareCEFSettings_RootCachePath_UsesXDGDataDir(t *testing.T) { | |
| 65 | 65 | homeDir := filepath.Join(t.TempDir(), "home") | |
| 66 | + | dataHome := filepath.Join(homeDir, ".local", "share") | |
| 66 | 67 | t.Setenv("HOME", homeDir) | |
| 67 | 68 | t.Setenv("ENV", "") | |
| 69 | + | t.Setenv("XDG_DATA_HOME", dataHome) | |
| 68 | 70 | ||
| 69 | 71 | logger := zerolog.Nop() | |
| 70 | 72 | settings, err := prepareCEFSettings(port.EngineOptions{}, RuntimeConfig{}, &logger) | |
| 71 | 73 | require.NoError(t, err) | |
| 72 | 74 | ||
| 73 | - | require.Equal(t, filepath.Join(homeDir, ".config", "cef_user_data"), settings.RootCachePath) | |
| 75 | + | require.Equal(t, filepath.Join(dataHome, "dumber", "cef_user_data"), settings.RootCachePath) | |
| 74 | 76 | } | |
| 75 | 77 | ||
| 76 | 78 | func TestPrepareCEFSettings_RootCachePath_DevMode(t *testing.T) { | |
| @@ -61,16 +61,18 @@ func TestPrepareCEFInitTraceFile_EnabledViaEnv(t *testing.T) { | |||||
| 61 | require.FileExists(t, path) | 61 | require.FileExists(t, path) | ||
| 62 | } | 62 | } | ||
| 63 | 63 | ||||
| 64 | - | func TestPrepareCEFSettings_RootCachePath_UsesLegacyCEFUserDataDir(t *testing.T) { | 64 | + | func TestPrepareCEFSettings_RootCachePath_UsesXDGDataDir(t *testing.T) { |
| 65 | homeDir := filepath.Join(t.TempDir(), "home") | 65 | homeDir := filepath.Join(t.TempDir(), "home") | ||
| 66 | + | dataHome := filepath.Join(homeDir, ".local", "share") | |||
| 66 | t.Setenv("HOME", homeDir) | 67 | t.Setenv("HOME", homeDir) | ||
| 67 | t.Setenv("ENV", "") | 68 | t.Setenv("ENV", "") | ||
| 69 | + | t.Setenv("XDG_DATA_HOME", dataHome) | |||
| 68 | 70 | ||||
| 69 | logger := zerolog.Nop() | 71 | logger := zerolog.Nop() | ||
| 70 | settings, err := prepareCEFSettings(port.EngineOptions{}, RuntimeConfig{}, &logger) | 72 | settings, err := prepareCEFSettings(port.EngineOptions{}, RuntimeConfig{}, &logger) | ||
| 71 | require.NoError(t, err) | 73 | require.NoError(t, err) | ||
| 72 | 74 | ||||
| 73 | - | require.Equal(t, filepath.Join(homeDir, ".config", "cef_user_data"), settings.RootCachePath) | 75 | + | require.Equal(t, filepath.Join(dataHome, "dumber", "cef_user_data"), settings.RootCachePath) |
| 74 | } | 76 | } | ||
| 75 | 77 | ||||
| 76 | func TestPrepareCEFSettings_RootCachePath_DevMode(t *testing.T) { | 78 | func TestPrepareCEFSettings_RootCachePath_DevMode(t *testing.T) { | ||