@@ -222,11 +222,29 @@ def get_cpython_dir(src_path: pathlib.Path) -> pathlib.Path:
222222# === Comparison utilities ===
223223
224224
225+ def _files_are_same (left : pathlib .Path , right : pathlib .Path ) -> bool :
226+ # Recheck contents even when size and timestamps match, including after a
227+ # previous comparison. filecmp caches results by those metadata alone.
228+ with left .open ("rb" ) as left_file , right .open ("rb" ) as right_file :
229+ while True :
230+ chunk = left_file .read (65536 )
231+ if chunk != right_file .read (65536 ):
232+ return False
233+ if not chunk :
234+ return True
235+
236+
225237def _dircmp_is_same (dcmp : filecmp .dircmp ) -> bool :
226238 """Recursively check if two directories are identical."""
227- if dcmp .diff_files or dcmp .left_only or dcmp .right_only :
239+ if dcmp .left_only or dcmp .right_only or dcmp .common_funny :
228240 return False
229241
242+ for name in dcmp .common_files :
243+ if not _files_are_same (
244+ pathlib .Path (dcmp .left ) / name , pathlib .Path (dcmp .right ) / name
245+ ):
246+ return False
247+
230248 for subdir in dcmp .subdirs .values ():
231249 if not _dircmp_is_same (subdir ):
232250 return False
@@ -236,14 +254,17 @@ def _dircmp_is_same(dcmp: filecmp.dircmp) -> bool:
236254
237255def compare_paths (cpython_path : pathlib .Path , local_path : pathlib .Path ) -> bool :
238256 """Compare a CPython path with a local path (file or directory)."""
239- if not local_path .exists ():
257+ if not cpython_path . exists () or not local_path .exists ():
240258 return False
241259
242- if cpython_path .is_file ():
243- return filecmp .cmp (cpython_path , local_path , shallow = False )
244-
245- dcmp = filecmp .dircmp (cpython_path , local_path )
246- return _dircmp_is_same (dcmp )
260+ try :
261+ if cpython_path .is_file ():
262+ return local_path .is_file () and _files_are_same (cpython_path , local_path )
263+ if not cpython_path .is_dir () or not local_path .is_dir ():
264+ return False
265+ return _dircmp_is_same (filecmp .dircmp (cpython_path , local_path ))
266+ except OSError :
267+ return False
247268
248269
249270def compare_file_contents (
0 commit comments