Skip to content

fix: resolve Windows path mismatch between setup write and runtime read#1712

Open
octo-patch wants to merge 1 commit intoWei-Shaw:mainfrom
octo-patch:fix/issue-1701-windows-path-setup-runtime-mismatch
Open

fix: resolve Windows path mismatch between setup write and runtime read#1712
octo-patch wants to merge 1 commit intoWei-Shaw:mainfrom
octo-patch:fix/issue-1701-windows-path-setup-runtime-mismatch

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1701

Problem

On Windows, the path /app/data resolves to the current drive root (e.g., C:\app\data), not a Docker-style path. This causes a divergence between:

  • Setup write path (GetDataDir()): falls back to current directory . when /app/data doesn't exist
  • Runtime read path (config.load()): always searches /app/data first in viper, then .

If the working directory changes between the initial setup and a subsequent restart (common when launching via double-click or as a Windows service), the runtime can end up looking in a completely different directory for config.yaml, causing the Setup Wizard to reappear.

Solution

  1. Restrict /app/data to Linux only in both GetDataDir() and the new getDataDir() helper in config.go. This eliminates the ambiguous path on Windows.

  2. Use the executable's directory as the primary fallback (before CWD). The exe directory is stable regardless of how the process is launched — direct double-click, service, or shell — making both setup and runtime always agree on the data location.

  3. Mirror path resolution in config.load() via a private getDataDir() helper that matches setup.GetDataDir() logic exactly, closing the divergence without introducing a circular import.

  4. Default timezone changed from Asia/Shanghai to UTC in setup.writeConfigFile() and timezone.Init(). Asia/Shanghai can cause startup failures on some Windows PostgreSQL configurations; UTC is universally accepted.

  5. OS-accurate restart message from the install API: Windows users are now told "Please restart the application manually." instead of the misleading "Service will restart automatically." The restart field in the JSON response also accurately reflects whether auto-restart is supported.

Testing

  • On Linux/Docker: /app/data is still checked first when it exists and is writable — no behavior change for the primary deployment target.
  • On Windows: both setup and runtime now use filepath.Dir(os.Executable()), so they always agree, regardless of CWD.
  • Existing unit test TestWriteConfigFileKeepsDefaultUserConcurrency continues to pass (it sets DATA_DIR which is handled before any platform-specific logic).

…ad (fixes Wei-Shaw#1701)

On Windows, the path /app/data resolves to the drive root (e.g., C:\app\data),
causing setup.GetDataDir() and config load() to potentially resolve to different
directories when the CWD changes between the initial setup and subsequent restarts.

Changes:
- Restrict /app/data check to Linux only in both GetDataDir() and load(),
  preventing the Windows path drift
- Use the executable's directory as the primary fallback instead of CWD,
  so both setup and runtime always agree on the data directory location
- Mirror the same path resolution logic in config.load() via a new getDataDir()
  helper, eliminating the divergence between the two codepaths
- Change the default timezone from Asia/Shanghai to UTC for cross-platform
  compatibility (Asia/Shanghai can fail on some Windows PostgreSQL setups)
- Return an OS-accurate restart message from the install API: Windows users
  are now told to restart manually instead of expecting automatic restart
- Improve the non-Linux log message in RestartService() for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows 下完成 Setup Wizard 后仍会重新进入安装向导(config.yaml / .installed 写入目录与启动读取目录不一致)

1 participant