Skip to content

Commit cc7c128

Browse files
fix: handle missing files and symlinks in code search and repo cloning
1 parent 9f2af71 commit cc7c128

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/seer/automation/codebase/code_search.py

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def search_file(self, file_path: str, keyword: str) -> Optional[SearchResult]:
9898
matches: List[Match] = []
9999

100100
try:
101+
if not os.path.exists(file_path):
102+
return None
103+
101104
if os.path.getsize(file_path) > self.max_file_size_bytes:
102105
logger.debug(f"Skipping {file_path} as it exceeds the maximum file size limit.")
103106
return None

src/seer/automation/codebase/repo_client.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,28 @@ def load_repo_to_tmp_dir(self, sha: str | None = None) -> tuple[str, str]:
301301
shutil.move(
302302
s, d
303303
) # move all directories from the root folder to the output directory
304+
elif os.path.islink(s):
305+
link_target = os.readlink(s)
306+
abs_target = os.path.normpath(os.path.join(os.path.dirname(s), link_target))
307+
if abs_target.startswith(root_folder_path):
308+
rel_target = os.path.relpath(abs_target, os.path.dirname(s))
309+
target_in_dest = os.path.join(os.path.dirname(d), rel_target)
310+
try:
311+
if os.path.exists(abs_target) and not os.path.exists(target_in_dest):
312+
target_dir = os.path.dirname(target_in_dest)
313+
os.makedirs(target_dir, exist_ok=True)
314+
shutil.copy2(abs_target, target_in_dest)
315+
os.symlink(rel_target, d)
316+
except OSError:
317+
if os.path.exists(abs_target):
318+
shutil.copy2(abs_target, d)
319+
else:
320+
if os.path.exists(abs_target):
321+
shutil.copy2(abs_target, d)
304322
else:
305-
# Skipping symlinks to prevent FileNotFoundError.
306-
if not os.path.islink(s):
307-
shutil.copy2(
308-
s, d
309-
) # copy all files from the root folder to the output directory
323+
shutil.copy2(
324+
s, d
325+
) # copy all files from the root folder to the output directory
310326

311327
shutil.rmtree(root_folder_path) # remove the root folder
312328

0 commit comments

Comments
 (0)