Skip to content

fix: add Windows support for config file locking#79

Open
sctmike wants to merge 1 commit intomarcus:mainfrom
sctmike:fix/windows-config-lock
Open

fix: add Windows support for config file locking#79
sctmike wants to merge 1 commit intomarcus:mainfrom
sctmike:fix/windows-config-lock

Conversation

@sctmike
Copy link
Copy Markdown

@sctmike sctmike commented Mar 26, 2026

Summary

config.go uses syscall.Flock and syscall.LOCK_EX directly, which are POSIX-only and don't exist on Windows. This causes a build failure:

# github.com/marcus/td/internal/config
config.go:92:20: undefined: syscall.Flock
config.go:92:47: undefined: syscall.LOCK_EX
config.go:95:16: undefined: syscall.Flock
config.go:95:43: undefined: syscall.LOCK_UN

This was introduced in ac37b22 (PR #12), even though db/lock_windows.go and serve/portfile_windows.go already had the correct platform-specific pattern.

Fix

Split withConfigLock out of config.go into:

  • config_lock_unix.go (//go:build unix) — original syscall.Flock implementation
  • config_lock_windows.go (//go:build windows) — uses windows.LockFileEx / windows.UnlockFileEx from golang.org/x/sys/windows

This matches the existing pattern in db/ and serve/.

Test plan

  • go build . succeeds on Windows (previously failed)
  • td version runs correctly from native Windows binary
  • Existing Unix builds unaffected (same code, just moved to build-tagged file)

config.go used syscall.Flock (POSIX-only), which fails to compile on
Windows. Split withConfigLock into platform-specific files using build
tags, matching the pattern already used in db/lock_windows.go and
serve/portfile_windows.go.
@marcus
Copy link
Copy Markdown
Owner

marcus commented Mar 26, 2026

Hey @sctmike! Starling here (AI assistant on the project). 👋

This is a solid fix — you've correctly identified that config.go was using syscall.Flock directly instead of the platform-specific pattern that db/ and serve/ already follow. The split into config_lock_unix.go / config_lock_windows.go with the right build tags is exactly the right approach.

Great that you verified go build and td version on native Windows — that's exactly the kind of confirmation we need for cross-platform fixes.

Flagging for Marcus to review and merge. Thanks for taking the time to track this down and submit the fix! ✦

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.

2 participants