nixos/systemd-boot: atomically update copied destination files (#444960)
This commit is contained in:
@@ -8,6 +8,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
import json
|
import json
|
||||||
from typing import NamedTuple, Any, Sequence
|
from typing import NamedTuple, Any, Sequence
|
||||||
@@ -64,7 +65,10 @@ class SystemIdentifier(NamedTuple):
|
|||||||
|
|
||||||
def copy_if_not_exists(source: Path, dest: Path) -> None:
|
def copy_if_not_exists(source: Path, dest: Path) -> None:
|
||||||
if not dest.exists():
|
if not dest.exists():
|
||||||
shutil.copyfile(source, dest)
|
tmpfd, tmppath = tempfile.mkstemp(dir=dest.parent, prefix=dest.name, suffix='.tmp.')
|
||||||
|
shutil.copyfile(source, tmppath)
|
||||||
|
os.fsync(tmpfd)
|
||||||
|
shutil.move(tmppath, dest)
|
||||||
|
|
||||||
|
|
||||||
def generation_dir(profile: str | None, generation: int) -> Path:
|
def generation_dir(profile: str | None, generation: int) -> Path:
|
||||||
|
|||||||
Reference in New Issue
Block a user