Skip to content

Commit

Permalink
flatmanager: Fix nesting of context managers
Browse files Browse the repository at this point in the history
appstream_gz and appstream_file are only needed for shutil.copyfileobj
so those two are joined together and added in the innermost position
while tempfile is kept in the outermost position.

Once shutil.copyfileobj is done both innermost handles are closed
automaitcally and the outermost handle can access the same resource
again
  • Loading branch information
bbhtt committed Oct 7, 2024
1 parent b23fbf5 commit 290d6b8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions flatpak_builder_lint/checks/flatmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ def check_repo(self, path: str) -> None:
self.errors.add("flat-manager-branch-repo-mismatch")
break

with (
tempfile.TemporaryDirectory() as tmpdir,
gzip.open(
f"{path}/appstream/{arches.pop()}/appstream.xml.gz", "rb"
) as appstream_gz,
open(f"{tmpdir}/appstream.xml", "wb") as appstream_file,
):
shutil.copyfileobj(appstream_gz, appstream_file)
with tempfile.TemporaryDirectory() as tmpdir:
with (
gzip.open(
f"{path}/appstream/{arches.pop()}/appstream.xml.gz", "rb"
) as appstream_gz,
open(f"{tmpdir}/appstream.xml", "wb") as appstream_file,
):
shutil.copyfileobj(appstream_gz, appstream_file)

if not appstream.has_manifest_key(f"{tmpdir}/appstream.xml"):
self.errors.add("appstream-no-flathub-manifest-key")
Expand Down

0 comments on commit 290d6b8

Please sign in to comment.