Windows Python tempfile permission error fix (#2309)

* Fix PermissionError: [Errno 13] Permission denied
Windows Python tempfile permission error fix
This commit is contained in:
ohyeah521
2023-12-19 00:28:24 -08:00
committed by GitHub
parent 1f8c6099bb
commit f465abd872
@@ -1,6 +1,7 @@
# -*- coding: utf_8 -*-
"""Module holding the functions for code analysis."""
import os
import logging
import tempfile
from pathlib import Path
@@ -37,9 +38,11 @@ def get_perm_rules(perm_rules, android_permissions):
dynamic_rules.append(p)
rules = yaml.dump(dynamic_rules)
if rules:
tmp = tempfile.NamedTemporaryFile(mode='w')
tmp = tempfile.NamedTemporaryFile(
mode='w',
delete=False)
tmp.write(rules)
tmp.flush()
tmp.close()
return tmp
except Exception:
logger.error('Getting Permission Rules')
@@ -98,7 +101,7 @@ def code_analysis(app_dir, typ, manifest_file, android_permissions):
[src],
{}))
logger.info('Android Permission Mapping Completed')
rule_file.close()
os.unlink(rule_file.name)
# NIAP Scan
niap_findings = niap_scan(
niap_rules.as_posix(),