Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions dracut-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1336,22 +1336,37 @@ inst_libdir_dir() {
# -n <pattern> install matching files
inst_libdir_file() {
local -a _files=()
local _path

# cache installed libdir files
if ! declare -p _libdir_file_cache 2> /dev/null | grep -q "declare -A"; then
declare -gxA _libdir_file_cache=()
fi

if [[ $1 == "-n" ]]; then
local _pattern=$2
shift 2
for _dir in $libdirs; do
for _i in "$@"; do
for _f in "${dracutsysrootdir-}$_dir"/$_i; do
[[ ${_f#"${dracutsysrootdir-}"} =~ $_pattern ]] || continue
[[ -e $_f ]] && _files+=("${_f#"${dracutsysrootdir-}"}")
_path="${_f#"${dracutsysrootdir-}"}"
if [[ -e $_f ]] && [[ ${_libdir_file_cache[$_path]:-} != 1 ]]; then
_files+=("$_path")
_libdir_file_cache[$_path]=1
fi
done
done
done
else
for _dir in $libdirs; do
for _i in "$@"; do
for _f in "${dracutsysrootdir-}$_dir"/$_i; do
[[ -e $_f ]] && _files+=("${_f#"${dracutsysrootdir-}"}")
_path="${_f#"${dracutsysrootdir-}"}"
if [[ -e $_f ]] && [[ ${_libdir_file_cache[$_path]:-} != 1 ]]; then
_files+=("$_path")
_libdir_file_cache[$_path]=1
fi
done
done
done
Expand Down
4 changes: 4 additions & 0 deletions test/test-functions
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ build_rootfs_base() {
# Include os-release to make systemd's initrd-switch-root.service happy
cp /usr/lib/os-release "$rootdir/usr/lib/os-release"

# Unset cache variables, otherwise successive calls to build_rootfs_base()
# to generate another initrd would not install the required files
unset _libdir_file_cache

if [[ "$(type -t inst_multiple 2> /dev/null)" != "function" ]]; then
# shellcheck source=./dracut-functions.sh
. "$PKGLIBDIR/dracut-functions.sh"
Expand Down
Loading