fix: Improve file path handling and logging for document scanning

• Convert relative paths to absolute paths
• Add logging for file scanning progress
• Log total number of new files found
• Enhance file scanning feedback
• Improve path resolution safety
This commit is contained in:
yangdx
2025-02-14 12:50:43 +08:00
parent 2c56141bfd
commit 258c7596e6

View File

@@ -564,6 +564,10 @@ def parse_args() -> argparse.Namespace:
args = parser.parse_args() args = parser.parse_args()
# conver relative path to absolute path
args.working_dir = os.path.abspath(args.working_dir)
args.input_dir = os.path.abspath(args.input_dir)
ollama_server_infos.LIGHTRAG_MODEL = args.simulated_model_name ollama_server_infos.LIGHTRAG_MODEL = args.simulated_model_name
return args return args
@@ -595,6 +599,7 @@ class DocumentManager:
"""Scan input directory for new files""" """Scan input directory for new files"""
new_files = [] new_files = []
for ext in self.supported_extensions: for ext in self.supported_extensions:
logger.info(f"Scanning for {ext} files in {self.input_dir}")
for file_path in self.input_dir.rglob(f"*{ext}"): for file_path in self.input_dir.rglob(f"*{ext}"):
if file_path not in self.indexed_files: if file_path not in self.indexed_files:
new_files.append(file_path) new_files.append(file_path)
@@ -1198,6 +1203,7 @@ def create_app(args):
new_files = doc_manager.scan_directory_for_new_files() new_files = doc_manager.scan_directory_for_new_files()
scan_progress["total_files"] = len(new_files) scan_progress["total_files"] = len(new_files)
logger.info(f"Found {len(new_files)} new files to index.")
for file_path in new_files: for file_path in new_files:
try: try:
with progress_lock: with progress_lock: