diff options
author | Leah Rowe <leah@libreboot.org> | 2025-08-23 15:35:47 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-08-23 15:38:29 +0100 |
commit | c12965f8e4205cc28d9f468891cd20330b28c53c (patch) | |
tree | b72ad2e1b8caff3e860de78726cb7e085fc029ec /include/lib.sh | |
parent | 7e6f52ec0a7a4106378191d352a862c0a03e71c4 (diff) |
lib.sh: safer pad_one_byte function
instead of copying to a temp file and then
concatenating with padding back to the main
file, we concatenate and create the temp file,
then move the temp file back to the main file.
this is because cat can be quite error prone,
more so than mv, so this will reduce the chance
of corrupt files being left behind depending
on the context (of course, the latter is often
avoided due to xbmk's design, which emphasises
use of temporary files first).
this matches the same design used in the function
unpad_one_byte, which creates the deconcatenated
output in a temporary file first, moving it back.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/lib.sh')
-rw-r--r-- | include/lib.sh | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/include/lib.sh b/include/lib.sh index 7215106c..f64a6a35 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -98,9 +98,8 @@ findpath() pad_one_byte() { paddedfile="`mktemp`" || err "mktemp pad_one_byte" - x_ cp "$1" "$paddedfile" - x_ cat "$paddedfile" config/data/coreboot/0 > "$1" || err "!pad $1"; : - x_ rm "$paddedfile" + x_ cat "$1" config/data/coreboot/0 > "$paddedfile" || err "!pad $1"; : + x_ mv "$paddedfile" "$1" } unpad_one_byte() |