Skip to content

Commit

Permalink
Fix potential race when loading temp CodeTF files
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Dec 14, 2023
1 parent e5853d2 commit 76d327e
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/pixee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,26 @@ def run_codemodder(
if verbose == 0 or verbose > 1:
common_codemodder_args.append("--verbose")

codetf = tempfile.NamedTemporaryFile()

num_codemods = len(codemods)

with Progress(disable=bool(verbose)) as progress:
task = progress.add_task(
f"Applying {num_codemods} {language} codemods",
total=num_codemods,
)
command = subprocess.Popen(
[codemodder, "--output", codetf.name, path] + common_codemodder_args,
stderr=subprocess.DEVNULL,
stdout=subprocess.PIPE if not verbose else None,
)
if command.stdout:
for line in iter(command.stdout.readline, b""):
if line.startswith(b"running codemod"):
progress.advance(task)
command.wait()
progress.update(task, completed=num_codemods)

return codetf
with tempfile.NamedTemporaryFile() as codetf:
with Progress(disable=bool(verbose)) as progress:
task = progress.add_task(
f"Applying {num_codemods} {language} codemods",
total=num_codemods,
)
command = subprocess.Popen(
[codemodder, "--output", codetf.name, path] + common_codemodder_args,
stderr=subprocess.DEVNULL,
stdout=subprocess.PIPE if not verbose else None,
)
if command.stdout:
for line in iter(command.stdout.readline, b""):
if line.startswith(b"running codemod"):
progress.advance(task)
command.wait()
progress.update(task, completed=num_codemods)
return json.load(codetf)


@main.command()
Expand Down Expand Up @@ -311,7 +309,7 @@ def fix(
continue

if glob(str(Path(path) / "**" / file_glob), recursive=True):
lang_codetf = run_codemodder(
results = run_codemodder(
lang,
codemodder,
path,
Expand All @@ -321,7 +319,6 @@ def fix(
dry_run,
verbose,
)
results = json.load(lang_codetf)
combined_codetf["results"].extend(results["results"])

elapsed = datetime.datetime.now() - start
Expand Down

0 comments on commit 76d327e

Please sign in to comment.