Skip to content

Commit a0f9678

Browse files
CopilotMte90
andcommitted
Final refinements: improve docstrings, use pipe separator, fix variable shadowing
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent 07bba09 commit a0f9678

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ async def lifespan(app: FastAPI):
6464
yield
6565

6666
# Stop FileWatcher on shutdown
67-
watcher = app_state.get_file_watcher()
68-
if watcher:
67+
shutdown_watcher = app_state.get_file_watcher()
68+
if shutdown_watcher:
6969
try:
70-
watcher.stop()
70+
shutdown_watcher.stop()
7171
logger.info("FileWatcher stopped successfully")
7272
except Exception as e:
7373
logger.error(f"Error stopping FileWatcher: {e}")

utils/file_watcher.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def set_on_change_callback(self, callback: Callable[[str, List[str]], None]) ->
201201
Set a callback to be called when changes are detected.
202202
203203
Args:
204-
callback: Function(project_id, changed_files) to call on changes
204+
callback: Function(project_id: str, changed_files: List[str]) to call on changes.
205+
changed_files is a list of relative file paths that changed.
205206
"""
206207
self._on_change_callback = callback
207208

@@ -316,11 +317,12 @@ def _scan_directory(self, directory: str) -> Dict[str, str]:
316317

317318
try:
318319
# Use both modification time and file size as signature
320+
# Format: "mtime|size" (using pipe as separator to avoid conflicts)
319321
stat = os.stat(filepath)
320322
mtime = stat.st_mtime
321323
size = stat.st_size
322324
relative_path = os.path.relpath(filepath, directory)
323-
file_hashes[relative_path] = f"{mtime}:{size}"
325+
file_hashes[relative_path] = f"{mtime}|{size}"
324326
except (OSError, ValueError):
325327
# Skip files we can't access
326328
continue

0 commit comments

Comments
 (0)