Python: Extract files in hidden dirs by default

Changes the default behaviour of the Python extractor so files inside
hidden directories are extracted by default.

Also adds an extractor option, `skip_hidden_directories`, which can be
set to `true` in order to revert to the old behaviour.

Finally, I made the logic surrounding what is logged in various cases a
bit more obvious.

Technically this changes the behaviour of the extractor (in that hidden
excluded files will now be logged as `(excluded)`, but I think this
makes more sense anyway.
This commit is contained in:
Taus
2025-04-29 15:12:38 +00:00
parent abbf753a09
commit 0c1b379ac1
2 changed files with 17 additions and 6 deletions

View File

@@ -83,11 +83,10 @@ class Traverser(object):
self.logger.debug("Ignoring %s (symlink)", fullpath)
continue
if isdir(fullpath):
if fullpath in self.exclude_paths or is_hidden(fullpath):
if is_hidden(fullpath):
self.logger.debug("Ignoring %s (hidden)", fullpath)
else:
self.logger.debug("Ignoring %s (excluded)", fullpath)
if fullpath in self.exclude_paths:
self.logger.debug("Ignoring %s (excluded)", fullpath)
elif is_hidden(fullpath):
self.logger.debug("Ignoring %s (hidden)", fullpath)
else:
empty = True
for item in self._treewalk(fullpath):
@@ -101,7 +100,12 @@ class Traverser(object):
self.logger.debug("Ignoring %s (filter)", fullpath)
if os.name== 'nt':
if os.environ.get("CODEQL_EXTRACTOR_PYTHON_OPTION_SKIP_HIDDEN_DIRECTORIES", "false") == "false":
def is_hidden(path):
return False
elif os.name== 'nt':
import ctypes
def is_hidden(path):