Skip to content

Conversation

@BHFock
Copy link
Owner

@BHFock BHFock commented Jul 30, 2025

This PR introduces a clutil_file_lock() context manager using fcntl to ensure exclusive access to the cl.json changelist file. It addresses race conditions that could occur when multiple git cl add/remove/delete processes run concurrently.

Changes:

  • Added clutil_file_lock() using @contextmanager and fcntl.flock()
  • Applied locking to clutil_load() and clutil_save() using a .lock file alongside cl.json
  • Explicitly set encoding='utf-8' to satisfy pylint W1514

Impact:

  • Ensures safe concurrent access to changelists
  • No behavioural changes for single-process usage
  • Unix-only (as fcntl is not available on Windows)

BHFock added 2 commits July 30, 2025 10:44
This patch introduces a file_lock() context manager using fcntl to ensure exclusive access to cl.json during read/write operations. It prevents race conditions when multiple git cl add/remove/delete processes run concurrently.

Lock file is created as cl.lock alongside cl.json
Locking is applied in clutil_load() and clutil_save()
Encoding explicitly set to utf-8 to satisfy pylint W1514
This change improves robustness in multi-process environments on Unix-like systems.
@BHFock BHFock merged commit 20109ea into main Jul 30, 2025
@BHFock BHFock deleted the lock branch July 30, 2025 10:15
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