Fix file handling on Windows for session registry#228
Conversation
Windows doesn't properly support Unix-style numeric file flags (O_CREAT,
O_EXCL, etc.) combined with Unix permission modes (0o600). This caused
EINVAL and ENOENT errors when users tried to launch ralph-tui on Windows.
The fix detects Windows via process.platform and uses string-based flags
('wx' for exclusive write, 'w' for write/truncate) instead of numeric
constants. Unix systems continue to use numeric flags with permissions.
Fixes #221
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughPlatform-specific file I/O handling was added to the session registry: Windows detection (IS_WINDOWS) drives use of 'wx' for lock acquisition and 'w' for temporary file writes; non-Windows paths keep the original numeric flags and FILE_MODE semantics. Changes
Sequence Diagram(s)(omitted — changes do not introduce a multi-component sequential flow requiring visualization) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
=======================================
Coverage 44.93% 44.93%
=======================================
Files 84 84
Lines 24479 24486 +7
=======================================
+ Hits 10999 11004 +5
- Misses 13480 13482 +2
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/session/registry.ts`:
- Around line 225-229: The Windows branch that opens the temp file omits the
FILE_MODE argument, so when IS_WINDOWS is true the call to open(tempPath, 'w')
should pass the same FILE_MODE used on Unix to ensure restrictive permissions;
update the code path that assigns tempHandle (the open call guarded by
IS_WINDOWS) to call open(tempPath, 'w', FILE_MODE) instead of open(tempPath,
'w'), keeping the existing Unix branch using constants.O_CREAT |
constants.O_WRONLY | constants.O_TRUNC and FILE_MODE unchanged.
Add tests that verify the string-based file flags ('wx', 'w') used on
Windows work correctly for lock acquisition and atomic write patterns.
These tests ensure >50% coverage on the new Windows-compatible code paths.
Add FILE_MODE parameter to the Windows branch of open() calls to maintain consistent permission handling across platforms, even though Windows ignores Unix-style permissions.
…21-7CZlY Fix file handling on Windows for session registry
Summary
Add platform-specific file handling to support Windows in the session registry module. Windows doesn't support Unix-style numeric file flags combined with permission modes, so this change uses string-based flags on Windows and numeric flags on Unix-like systems.
Changes
IS_WINDOWSplatform detection constant to identify Windows systemsacquireLock()to use'wx'flag on Windows instead ofO_CREAT | O_EXCL | O_WRONLYwith FILE_MODEsaveRegistryInternal()to use'w'flag on Windows instead ofO_CREAT | O_WRONLY | O_TRUNCwith FILE_MODEImplementation Details
The changes maintain the same semantic behavior across platforms:
'wx'on Windows,O_CREAT | O_EXCL | O_WRONLYon Unix)'w'on Windows,O_CREAT | O_WRONLY | O_TRUNCon Unix)Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.