Skip to content

Default config path uses forward slashes on Windows, producing mixed-separator paths #441

@hazelmayank

Description

@hazelmayank

Description

Image

On Windows, the CLI displays mixed-separator filesystem paths when computing the
default config location. The home portion uses backslashes (correctly, from
os.UserHomeDir()), but everything appended afterwards uses forward slashes.

This happens because pkg/config/localconfig.go uses the path package for
filesystem paths. From the Go documentation:

Package path implements utility routines for manipulating slash-separated
paths, such as paths in URLs. The path/filepath package should be used
for paths that interact with the operating system's filesystem.

https://pkg.go.dev/path

path.Join always uses / regardless of OS. The correct API for filesystem
paths is filepath.Join, which uses the OS-specific separator.

Affected code

pkg/config/localconfig.go uses path.Join / path.Dir in six places:

  • Line 112 — DefaultConfigDir: path.Join(homeDir, ".config", "microcks")
  • Line 133 — DefaultLocalConfigPath: path.Join(dir, "config")
  • Line 142 — DefaultLocalWatchPath: path.Join(dir, "watch")
  • Line 158 — WriteLocalConfig: path.Dir(configPath)
  • Line 410 — WriteLocalWatchConfig: path.Dir(cfgPath)
  • Line 6 — import "path"

Reproduction (Windows 11, PowerShell or cmd)

> .\microcks.exe --help
...
      --config string   Path to Microcks config (default "C:\Users\<USER>/.config/microcks/config")
                                                                  ^   ^   forward slash after the user dir
> .\microcks.exe context
2026/05/27 00:35:59 No contexts defined in C:\Users\<USER>/.config/microcks/config

Expected

C:\Users\<USER>\.config\microcks\config

Proposed fix

Replace the path package with path/filepath for all filesystem path
construction in pkg/config/localconfig.go. The semantics are identical on
Unix (both produce /-separated paths) and correct on Windows.

I'm happy to send a PR if maintainers agree.

Environment

  • OS: Windows 11
  • Go: go1.26.2 windows/amd64
  • Branch: main (development version 1.0.3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions