mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 04:35:41 +03:00
maintainers/scripts/sha-to-sri: fix file-descriptor leak
This commit is contained in:
parent
c425822e17
commit
915799a2b9
1 changed files with 9 additions and 8 deletions
|
@ -173,17 +173,18 @@ def atomicFileUpdate(target: Path):
|
||||||
raised, `new` (atomically) replaces the `target`, otherwise it is deleted.
|
raised, `new` (atomically) replaces the `target`, otherwise it is deleted.
|
||||||
"""
|
"""
|
||||||
# That's mostly copied from noto-emoji.py, should DRY it out
|
# That's mostly copied from noto-emoji.py, should DRY it out
|
||||||
from tempfile import mkstemp
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
fd, _p = mkstemp(
|
|
||||||
dir = target.parent,
|
|
||||||
prefix = target.name,
|
|
||||||
)
|
|
||||||
tmpPath = Path(_p)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with target.open() as original:
|
with target.open() as original:
|
||||||
with tmpPath.open("w") as new:
|
with NamedTemporaryFile(
|
||||||
|
dir = target.parent,
|
||||||
|
prefix = target.stem,
|
||||||
|
suffix = target.suffix,
|
||||||
|
delete = False,
|
||||||
|
mode="w", # otherwise the file would be opened in binary mode by default
|
||||||
|
) as new:
|
||||||
|
tmpPath = Path(new.name)
|
||||||
yield (original, new)
|
yield (original, new)
|
||||||
|
|
||||||
tmpPath.replace(target)
|
tmpPath.replace(target)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue