Skip to content

Commit 3710680

Browse files
committed
fix:remove eduplication in watch directory
1 parent 017a7c0 commit 3710680

5 files changed

Lines changed: 503 additions & 48 deletions

File tree

CHANGES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [0.2.1] - 2025-09-10
4+
5+
### Bug Fixes
6+
- **Directory Monitoring**: Fixed deduplication issue in watch directory functionality
7+
- Removed unnecessary event deduplication that was causing missed file changes
8+
- Improved callback handling to ensure all file events are properly reported
9+
- Enhanced error handling in directory monitoring callbacks
10+
11+
### Testing
12+
- Enhanced test coverage for directory monitoring functionality
13+
- Added comprehensive file modification monitoring tests
14+
- Improved integration test reliability
15+
316
## [0.2.0] - 2025-09-08
417

518
### New Features

agb/modules/file_system.py

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,6 @@ def watch_directory(
996996

997997
def _monitor_directory():
998998
"""Internal function to monitor directory changes."""
999-
last_events = [] # Track last batch of events for deduplication
1000-
1001999
print(f"Starting directory monitoring for: {path}")
10021000
print(f"Polling interval: {interval} seconds")
10031001

@@ -1007,24 +1005,17 @@ def _monitor_directory():
10071005
result = self._get_file_change(path)
10081006

10091007
if result.success:
1010-
# Check if current events are different from last events
10111008
current_events = result.events
10121009

1013-
# Compare with last events to avoid duplicates
1014-
if self._events_different(current_events, last_events):
1015-
print(f"Detected {len(current_events)} file changes (different from last):")
1016-
for event in current_events:
1017-
print(f" - {event}")
1018-
1019-
try:
1020-
callback(current_events)
1021-
except Exception as e:
1022-
print(f"Error in callback function: {e}")
1023-
1024-
# Update last events
1025-
last_events = current_events[:]
1026-
else:
1027-
print(f"Received {len(current_events)} events, but they are identical to last batch - skipping")
1010+
# Always call callback with current events (no deduplication)
1011+
print(f"Detected {len(current_events)} file changes:")
1012+
for event in current_events:
1013+
print(f" - {event}")
1014+
1015+
try:
1016+
callback(current_events)
1017+
except Exception as e:
1018+
print(f"Error in callback function: {e}")
10281019

10291020
else:
10301021
print(f"Error monitoring directory: {result.error_message}")
@@ -1054,32 +1045,5 @@ def _monitor_directory():
10541045

10551046
return monitor_thread
10561047

1057-
def _events_different(self, current_events: List[FileChangeEvent], last_events: List[FileChangeEvent]) -> bool:
1058-
"""
1059-
Compare two lists of events to determine if they are different.
1060-
1061-
Args:
1062-
current_events: Current batch of events
1063-
last_events: Previous batch of events
1064-
1065-
Returns:
1066-
bool: True if events are different, False if they are the same
1067-
"""
1068-
# If lengths are different, events are different
1069-
if len(current_events) != len(last_events):
1070-
return True
1071-
1072-
# If both are empty, they are the same
1073-
if len(current_events) == 0:
1074-
return False
1075-
1076-
# Compare each event
1077-
for current_event, last_event in zip(current_events, last_events):
1078-
if (current_event.event_type != last_event.event_type or
1079-
current_event.path != last_event.path or
1080-
current_event.path_type != last_event.path_type):
1081-
return True
1082-
1083-
# All events are identical
1084-
return False
1048+
10851049

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"pydantic>=2.0",
2929
"aiohttp>=3.12.5",
3030
]
31-
version = "0.2.0"
31+
version = "0.2.1"
3232

3333
[project.optional-dependencies]
3434
test = [

0 commit comments

Comments
 (0)