diff --git a/hindsight-embed/hindsight_embed/profile_manager.py b/hindsight-embed/hindsight_embed/profile_manager.py index d208b01b3..3ed62b749 100644 --- a/hindsight-embed/hindsight_embed/profile_manager.py +++ b/hindsight-embed/hindsight_embed/profile_manager.py @@ -4,11 +4,13 @@ Each profile has its own config, daemon lock, log file, and port. """ -import fcntl import hashlib import json import os import sys + +if sys.platform != "win32": + import fcntl from dataclasses import dataclass, field from datetime import datetime, timezone from pathlib import Path @@ -470,8 +472,9 @@ def _save_metadata(self, metadata: ProfileMetadata): temp_file = metadata_file.with_suffix(".json.tmp") with open(temp_file, "w") as f: - # Acquire exclusive lock - fcntl.flock(f.fileno(), fcntl.LOCK_EX) + # Acquire exclusive lock (Unix only — Windows uses atomic rename for safety) + if sys.platform != "win32": + fcntl.flock(f.fileno(), fcntl.LOCK_EX) try: json.dump( {"version": metadata.version, "profiles": metadata.profiles}, @@ -481,7 +484,8 @@ def _save_metadata(self, metadata: ProfileMetadata): f.flush() os.fsync(f.fileno()) finally: - fcntl.flock(f.fileno(), fcntl.LOCK_UN) + if sys.platform != "win32": + fcntl.flock(f.fileno(), fcntl.LOCK_UN) # Atomic rename temp_file.rename(metadata_file)