Skip to content

Commit

Permalink
Merge pull request fluidattacks#1160 from rohaquinlop/issue-1159-exce…
Browse files Browse the repository at this point in the history
…ssive

feat(build): fluidattacks#1159 excessive privileges
  • Loading branch information
dsalaza4 authored Sep 21, 2023
2 parents 8e5b6cc + f40747b commit ad02da4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/cli/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import tempfile
import textwrap
from time import (
sleep,
time,
)
from tui import (
Expand Down Expand Up @@ -411,11 +412,33 @@ class Config(NamedTuple):
cache: List[Dict[str, str]]


def _get_named_temporary_file_name() -> str:
attempts = 0
file_name = ""
success = False
while attempts < 5 and not success:
try:
with tempfile.NamedTemporaryFile(delete=True) as file:
file_name = file.name
success = True
except FileExistsError as error:
CON.print(
f"Failed to create {error.filename}, retrying in 1 second..."
)
attempts += 1
sleep(1)

if not success:
raise FileExistsError("Could not create file after 5 attempts.")
return file_name


def _get_config(head: str, attr_paths: str) -> Config:
CON.out()
CON.rule("Building project configuration")
CON.out()
out: str = tempfile.mktemp() # nosec

out: str = _get_named_temporary_file_name()
code = _run(
args=_nix_build(
attr="config.configAsJson"
Expand Down

0 comments on commit ad02da4

Please sign in to comment.