Skip to content

Commit b0748b5

Browse files
committed
Extractor: normalize path when checking against overlay changed files
1 parent 8e41e6e commit b0748b5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

python/extractor/semmle/traverser.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, options, modulenames, logger):
4040
with open(overlay_changes_file, 'r', encoding='utf-8') as f:
4141
data = json.load(f)
4242
changed_paths = data.get('changes', [])
43-
self.overlay_changes = { os.path.abspath(p) for p in changed_paths }
43+
self.overlay_changes = { os.path.normcase(os.path.normpath(os.path.abspath(p))) for p in changed_paths }
4444
except (IOError, ValueError) as e:
4545
logger.warn("Failed to read overlay changes from '%s' (falling back to full extraction): %s", overlay_changes_file, e)
4646
self.overlay_changes = None
@@ -62,18 +62,18 @@ def __iter__(self):
6262
if mod is None:
6363
self.logger.error("No module named '%s'.", name)
6464
raise ExtractorFailure()
65-
if self.overlay_changes is not None and mod.path not in self.overlay_changes:
65+
if not self._changed_in_overlay(mod.path):
6666
self.logger.debug("Skipping module '%s' as it was not changed in overlay extraction.", name)
6767
continue
6868
yield mod.get_extractable()
6969
for path in self.paths:
70-
if self.overlay_changes is not None and path not in self.overlay_changes:
70+
if not self._changed_in_overlay(path):
7171
self.logger.debug("Skipping path '%s' as it was not changed in overlay extraction.", path)
7272
continue
7373
yield Extractable.from_path(path)
7474
for path in self.recurse_files:
7575
for modpath in self._treewalk(path):
76-
if self.overlay_changes is not None and modpath not in self.overlay_changes:
76+
if not self._changed_in_overlay(modpath):
7777
self.logger.debug("Skipping file '%s' as it was not changed in overlay extraction.", modpath)
7878
continue
7979
yield Extractable.from_path(modpath)
@@ -89,11 +89,15 @@ def __iter__(self):
8989
self.logger.error("Package '%s' does not have a path.", name)
9090
raise ExtractorFailure()
9191
for modpath in self._treewalk(path):
92-
if self.overlay_changes is not None and modpath not in self.overlay_changes:
92+
if not self._changed_in_overlay(modpath):
9393
self.logger.debug("Skipping package '%s' as it was not changed in overlay extraction.", modpath)
9494
continue
9595
yield Extractable.from_path(modpath)
9696

97+
def _changed_in_overlay(self, path):
98+
return self.overlay_changes is None or \
99+
os.path.normcase(os.path.normpath(os.path.abspath(path))) in self.overlay_changes
100+
97101
def _treewalk(self, path):
98102
'''Recursively walk the directory tree, skipping sym-links and
99103
hidden files and directories.'''

0 commit comments

Comments
 (0)