xbmk: don't call mkdir. use xbmkdir (new function)

xbmkdir checks if a directory exists, before running
mkdir, and then still uses -p

i was testing xbmk on arch linux today, and noticed
that it errored out when a directory already exists.

i'm mitigating against buggy or differently behaving
mkdir implementations this way, by wrapping around
it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2025-10-04 22:36:11 +01:00
parent f358cfaa55
commit c1d6cd22c2
8 changed files with 33 additions and 21 deletions
+4 -4
View File
@@ -81,7 +81,7 @@ git_prep()
fi fi
if [ "$_loc" != "${_loc%/*}" ]; then if [ "$_loc" != "${_loc%/*}" ]; then
x_ mkdir -p "${_loc%/*}" x_ xbmkdir "${_loc%/*}"
fi fi
x_ mv "$tmpgit" "$_loc" x_ mv "$tmpgit" "$_loc"
} }
@@ -198,7 +198,7 @@ try_fetch_git()
cached="${cached%.git}" cached="${cached%.git}"
cached="$XBMK_CACHE/$cached" cached="$XBMK_CACHE/$cached"
x_ mkdir -p "${5%/*}" "${cached%/*}" x_ xbmkdir "${5%/*}" "${cached%/*}"
if ! try_$2 "$cached" "$@"; then if ! try_$2 "$cached" "$@"; then
return 1 return 1
@@ -221,7 +221,7 @@ try_fetch_file()
cached="file/$6" cached="file/$6"
cached="$XBMK_CACHE/$cached" cached="$XBMK_CACHE/$cached"
x_ mkdir -p "${5%/*}" "${cached%/*}" x_ xbmkdir "${5%/*}" "${cached%/*}"
if bad_checksum "$6" "$cached" 2>/dev/null; then if bad_checksum "$6" "$cached" 2>/dev/null; then
x_ rm -f "$cached" x_ rm -f "$cached"
@@ -284,7 +284,7 @@ try_git()
if [ ! -d "$gitdest" ]; then if [ ! -d "$gitdest" ]; then
( x_ git clone "$2" "$tmpgitcache" ) || return 1 ( x_ git clone "$2" "$tmpgitcache" ) || return 1
x_ mkdir -p "${gitdest%/*}" x_ xbmkdir "${gitdest%/*}"
x_ mv "$tmpgitcache" "$gitdest" x_ mv "$tmpgitcache" "$gitdest"
fi fi
+1 -1
View File
@@ -58,7 +58,7 @@ xbmk_init()
fi fi
export PWD="$xbmkpwd" export PWD="$xbmkpwd"
x_ mkdir -p "$basetmp" x_ xbmkdir "$basetmp"
for init_cmd in get_version set_env set_threads git_init child_exec; do for init_cmd in get_version set_env set_threads git_init child_exec; do
if ! xbmk_$init_cmd "$@"; then if ! xbmk_$init_cmd "$@"; then
+19 -7
View File
@@ -8,12 +8,6 @@
cbfstool="elf/coreboot/default/cbfstool" cbfstool="elf/coreboot/default/cbfstool"
rmodtool="elf/coreboot/default/rmodtool" rmodtool="elf/coreboot/default/rmodtool"
remkdir()
{
x_ rm -Rf "$@"
x_ mkdir -p "$@"
}
mkrom_tarball() mkrom_tarball()
{ {
update_xbmkver "$1" update_xbmkver "$1"
@@ -58,7 +52,7 @@ mktarball()
printf "Creating tar archive '%s' from directory '%s'\n" "$2" "$1" printf "Creating tar archive '%s' from directory '%s'\n" "$2" "$1"
if [ "${2%/*}" != "$2" ]; then if [ "${2%/*}" != "$2" ]; then
x_ mkdir -p "${2%/*}" x_ xbmkdir "${2%/*}"
fi fi
x_ tar -c "$1" | xz -T$XBMK_THREADS -9e > "$2" || \ x_ tar -c "$1" | xz -T$XBMK_THREADS -9e > "$2" || \
@@ -169,6 +163,24 @@ build_sbase()
fi fi
} }
remkdir()
{
x_ rm -Rf "$@"
x_ xbmkdir "$@"
}
xbmkdir()
{
while [ $# -gt 0 ]
do
if [ ! -d "$1" ]; then
x_ mkdir -p "$1"
fi
shift 1
done
}
fx_() fx_()
{ {
xchk fx_ "$@" xchk fx_ "$@"
+1 -1
View File
@@ -22,7 +22,7 @@ extract_refcode()
err "cbfstoolref not set" "extract_refcode" "$@" err "cbfstoolref not set" "extract_refcode" "$@"
fi fi
x_ mkdir -p "${_pre_dest%/*}" x_ xbmkdir "${_pre_dest%/*}"
x_ "$cbfstoolref" "$appdir/bios.bin" extract \ x_ "$cbfstoolref" "$appdir/bios.bin" extract \
-m x86 -n fallback/refcode -f "$appdir/ref" -r RO_SECTION -m x86 -n fallback/refcode -f "$appdir/ref" -r RO_SECTION
+1 -1
View File
@@ -52,7 +52,7 @@ release()
fi fi
x_ rm -Rf "$rsrc" x_ rm -Rf "$rsrc"
x_ mkdir -p "$reldir" x_ xbmkdir "$reldir"
x_ mv "$vdir" "$reldir" x_ mv "$vdir" "$reldir"
x_ rm -Rf "${vdir%"/$version"}" x_ rm -Rf "${vdir%"/$version"}"
+3 -3
View File
@@ -19,7 +19,7 @@ buildser()
x_ make -C "$sersrc" BOARD=$2 x_ make -C "$sersrc" BOARD=$2
fi fi
x_ mkdir -p "bin/serprog_$1" x_ xbmkdir "bin/serprog_$1"
x_ mv "$serx" "bin/serprog_$1/serprog_$2.${serx##*.}" x_ mv "$serx" "bin/serprog_$1/serprog_$2.${serx##*.}"
} }
@@ -119,7 +119,7 @@ check_coreboot_util()
return 0 return 0
fi fi
x_ mkdir -p "$utilelfdir" x_ xbmkdir "$utilelfdir"
x_ cp "$utilsrcdir/$1" "$utilelfdir" x_ cp "$utilsrcdir/$1" "$utilelfdir"
if [ "$1" = "cbfstool" ]; then if [ "$1" = "cbfstool" ]; then
@@ -453,7 +453,7 @@ cprom()
printf "Creating new %s image: '%s'\n" "$projectname" "$newrom" printf "Creating new %s image: '%s'\n" "$projectname" "$newrom"
x_ mkdir -p "bin/$target" x_ xbmkdir "bin/$target"
x_ $cpcmd "$irom" "$newrom" x_ $cpcmd "$irom" "$newrom"
} }
+3 -3
View File
@@ -432,7 +432,7 @@ project_up_to_date()
shift 3 shift 3
x_ mkdir -p "$XBMK_CACHE/$hashdir" x_ xbmkdir "$XBMK_CACHE/$hashdir"
if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
read -r old_hash < "$XBMK_CACHE/$hashdir/$project$hashname" \ read -r old_hash < "$XBMK_CACHE/$hashdir/$project$hashname" \
@@ -485,7 +485,7 @@ check_cross_compiler()
xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS" xgccargs="crossgcc-$xfix UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
x_ ./mk -f coreboot "${cbdir#src/coreboot/}" x_ ./mk -f coreboot "${cbdir#src/coreboot/}"
x_ mkdir -p "elf/coreboot/$tree" # TODO: is this needed? x_ xbmkdir "elf/coreboot/$tree" # TODO: is this needed?
export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH" export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH"
export CROSS_COMPILE="${xarch% *}-" export CROSS_COMPILE="${xarch% *}-"
@@ -748,7 +748,7 @@ check_makefile()
copy_elf() copy_elf()
{ {
if [ -f "$listfile" ]; then if [ -f "$listfile" ]; then
x_ mkdir -p "$dest_dir" x_ xbmkdir "$dest_dir"
fi fi
if [ -f "$listfile" ]; then if [ -f "$listfile" ]; then
+1 -1
View File
@@ -217,7 +217,7 @@ fetch()
return 0 return 0
fi fi
x_ mkdir -p "${_dest%/*}" x_ xbmkdir "${_dest%/*}"
if [ "$dl_type" != "fsp" ]; then if [ "$dl_type" != "fsp" ]; then
extract_archive "$_dl" "$appdir" || \ extract_archive "$_dl" "$appdir" || \