mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-04 19:55:00 +00:00
refactor: simplify directory handling in FileWatcher class
This commit is contained in:
parent
496b92536f
commit
8cf72a4409
1 changed files with 4 additions and 6 deletions
|
@ -67,10 +67,8 @@ class FileWatcher:
|
||||||
|
|
||||||
def __init__(self, coder, encoding="utf-8", gitignores=None):
|
def __init__(self, coder, encoding="utf-8", gitignores=None):
|
||||||
self.coder = coder
|
self.coder = coder
|
||||||
self.directory = coder.root
|
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
self.root = Path(self.directory)
|
self.root = Path(coder.root)
|
||||||
self.root_abs = self.root.absolute()
|
|
||||||
self.stop_event = None
|
self.stop_event = None
|
||||||
self.watcher_thread = None
|
self.watcher_thread = None
|
||||||
self.changed_files = None
|
self.changed_files = None
|
||||||
|
@ -83,10 +81,10 @@ class FileWatcher:
|
||||||
path_obj = Path(path)
|
path_obj = Path(path)
|
||||||
path_abs = path_obj.absolute()
|
path_abs = path_obj.absolute()
|
||||||
|
|
||||||
if not path_abs.is_relative_to(self.root_abs):
|
if not path_abs.is_relative_to(self.root.absolute()):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
rel_path = path_abs.relative_to(self.root_abs)
|
rel_path = path_abs.relative_to(self.root)
|
||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
dump(rel_path)
|
dump(rel_path)
|
||||||
|
|
||||||
|
@ -128,7 +126,7 @@ class FileWatcher:
|
||||||
def watch_files():
|
def watch_files():
|
||||||
try:
|
try:
|
||||||
for changes in watch(
|
for changes in watch(
|
||||||
self.root, watch_filter=filter_func, stop_event=self.stop_event
|
str(self.root), watch_filter=filter_func, stop_event=self.stop_event
|
||||||
):
|
):
|
||||||
changed_files = {str(Path(change[1])) for change in changes}
|
changed_files = {str(Path(change[1])) for change in changes}
|
||||||
result = {}
|
result = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue