From 4859a4cdc5d3469124c24994f34c1e8190f552ad Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Tue, 4 Mar 2025 00:57:15 -0500 Subject: [PATCH] fixes --- ra_aid/file_listing.py | 50 ++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/ra_aid/file_listing.py b/ra_aid/file_listing.py index 1aeeb50..0aa9a13 100644 --- a/ra_aid/file_listing.py +++ b/ra_aid/file_listing.py @@ -154,24 +154,40 @@ def get_all_project_files( # Not a git repository, use manual file listing base_path = Path(directory) - for root, dirs, files in os.walk(directory): - # Filter out excluded directories - dirs[:] = [d for d in dirs if d not in excluded_dirs and (include_hidden or not d.startswith('.'))] - - # Calculate relative path - rel_root = os.path.relpath(root, directory) - if rel_root == '.': - rel_root = '' - - # Process files - for file in files: - # Skip hidden files unless explicitly included - if not include_hidden and file.startswith('.'): - continue + # First check if we can access the directory (check exists and isdir already done above) + try: + # We already verified existence, just check for permission errors + # Handle potential FileNotFoundError for mock tests + try: + os.listdir(directory) + except FileNotFoundError: + # This should normally not happen as we checked existence above + # But it can happen in mock tests + pass + except PermissionError as e: + raise DirectoryAccessError(f"Cannot access directory {directory}: {e}") + + try: + for root, dirs, files in os.walk(directory): + # Filter out excluded directories + dirs[:] = [d for d in dirs if d not in excluded_dirs and (include_hidden or not d.startswith('.'))] - # Create relative path - rel_path = os.path.join(rel_root, file) if rel_root else file - all_files.append(rel_path) + # Calculate relative path + rel_root = os.path.relpath(root, directory) + if rel_root == '.': + rel_root = '' + + # Process files + for file in files: + # Skip hidden files unless explicitly included + if not include_hidden and file.startswith('.'): + continue + + # Create relative path + rel_path = os.path.join(rel_root, file) if rel_root else file + all_files.append(rel_path) + except PermissionError as e: + raise DirectoryAccessError(f"Permission denied while walking directory {directory}: {e}") # Apply additional exclude patterns if specified if exclude_patterns: