mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
watch service
This commit is contained in:
@@ -2,6 +2,38 @@
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Set, Dict, Optional
|
||||
from watchfiles import Change
|
||||
from basic_memory.services.file_service import FileService
|
||||
|
||||
|
||||
@dataclass
|
||||
class FileChange:
|
||||
"""A change to a file detected by the watch service.
|
||||
|
||||
Attributes:
|
||||
change_type: Type of change (added, modified, deleted)
|
||||
path: Path to the file
|
||||
checksum: File checksum (None for deleted files)
|
||||
"""
|
||||
change_type: Change
|
||||
path: str
|
||||
checksum: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
async def from_path(cls, path: str, change_type: Change, file_service: FileService) -> "FileChange":
|
||||
"""Create FileChange from a path, computing checksum if file exists.
|
||||
|
||||
Args:
|
||||
path: Path to the file
|
||||
change_type: Type of change detected
|
||||
file_service: Service to read file and compute checksum
|
||||
|
||||
Returns:
|
||||
FileChange with computed checksum for non-deleted files
|
||||
"""
|
||||
file_path = file_service.path(path)
|
||||
content, checksum = await file_service.read_file(file_path) if change_type != Change.deleted else (None, None)
|
||||
return cls(path=file_path, change_type=change_type, checksum=checksum)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -18,7 +50,7 @@ class SyncReport:
|
||||
new: Set[str] = field(default_factory=set)
|
||||
modified: Set[str] = field(default_factory=set)
|
||||
deleted: Set[str] = field(default_factory=set)
|
||||
moves: Dict[str, str] = field(default_factory=dict) # old_path -> new_path
|
||||
moves: Dict[str, str] = field(default_factory=dict) # old_path -> new_path
|
||||
checksums: Dict[str, str] = field(default_factory=dict)
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user