Skip to content

Commit e2f6e4a

Browse files
committed
Revert "Extractor: use filesystem-canonical path comparison to determine built-in files"
This reverts commit 01cf7e9.
1 parent 4a87104 commit e2f6e4a

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

python/extractor/semmle/extractors/builtin_extractor.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import sys
2-
import os
3-
from pathlib import Path
42
from semmle import util
53
from semmle.python.passes.objects import ObjectPass
64
from semmle.extractors.base import BaseExtractor
@@ -19,7 +17,7 @@ def process(self, unit):
1917
# Modules in the standard library (e.g. `os`)
2018
if not self.options.extract_stdlib and \
2119
isinstance(unit, util.FileExtractable) and \
22-
_is_subpath(unit.path, util.STDLIB_PATH):
20+
unit.path.startswith(util.STDLIB_PATH):
2321
return SkippedBuiltin
2422
if not isinstance(unit, util.BuiltinModuleExtractable):
2523
return NotImplemented
@@ -41,18 +39,3 @@ def process(self, unit):
4139

4240
def close(self):
4341
pass
44-
45-
def _is_subpath(path, prefix):
46-
# Prefer filesystem-canonical comparison when possible
47-
try:
48-
p = Path(path).resolve()
49-
q = Path(prefix).resolve()
50-
return p == q or q in p.parents
51-
except OSError:
52-
# Fallback for non-existent paths: normalize and compare strings
53-
p_str = os.path.normcase(os.path.normpath(os.path.abspath(path)))
54-
q_str = os.path.normcase(os.path.normpath(os.path.abspath(prefix)))
55-
# Ensure prefix is a directory boundary
56-
if not q_str.endswith(os.path.sep):
57-
q_str = q_str + os.path.sep
58-
return p_str == q_str.rstrip(os.path.sep) or p_str.startswith(q_str)

0 commit comments

Comments
 (0)