Skip to content

Commit aeb666b

Browse files
committed
dkms: do_uninstall: restore archived modules to recorded location
Fixes: dell#480
1 parent 95d380e commit aeb666b

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

dkms.in

+24
Original file line numberDiff line numberDiff line change
@@ -1888,9 +1888,33 @@ do_uninstall()
18881888
else
18891889
echo "Module $m$module_suffix was not found within $install_tree/$1/"
18901890
fi
1891+
if [[ -d $original_module_backup_dir ]]; then
1892+
local origin_file
1893+
while IFS= read -r origin_file
1894+
do
1895+
[[ $origin_file ]] || continue
1896+
local original_module
1897+
original_module=${origin_file%.origin}
1898+
[[ -f $original_module ]] || continue
1899+
local original_location
1900+
original_location=$(head -n 1 "$origin_file")
1901+
case $original_location in
1902+
"$install_tree/$1/"*)
1903+
echo "Restoring archived original module $original_location"
1904+
mkdir -p "${original_location%/*}"
1905+
mv -f "$original_module" "$original_location"
1906+
rm -f "$origin_file"
1907+
;;
1908+
*) warn "Bad original location '$original_location' in $origin_file"
1909+
;;
1910+
esac
1911+
done <<< "$(find "$original_module_backup_dir" -type f -name "$m.*.origin")"
1912+
find "${original_module_backup_dir%/*}" -type d -empty -delete
1913+
fi
18911914
local origmod
18921915
origmod=$(compressed_or_uncompressed "$original_module_backup_dir" "$m")
18931916
if [[ -n $origmod ]]; then
1917+
# Module was archived by older dkms versions without creating .origin
18941918
echo "Restoring archived original module"
18951919
mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
18961920
mv -f "$origmod" "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/" 2>/dev/null

run_test.sh

+4-23
Original file line numberDiff line numberDiff line change
@@ -1855,20 +1855,9 @@ run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_replace_test -v
18551855
Module dkms_replace_test/2.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}):
18561856
Before uninstall, this module version was ACTIVE on this kernel.
18571857
Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
1858-
Restoring archived original module
1859-
Running depmod... done.
1860-
Removing original module(s) from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH})
1861-
EOF
1862-
if [ "${expected_dest_loc}" != "kernel/extra" ]; then
1863-
# A replaced module originating from a kernel image should get restored
1864-
# to its original location, but since we are testing with a dkms module
1865-
# (installed to a dynamic location), this may not happen.
1866-
echo 'Moving the restored module back to its correct location (testing artefact)'
1867-
mkdir -p "/lib/modules/${KERNEL_VER}/${expected_dest_loc}"
1868-
mv "/lib/modules/${KERNEL_VER}/kernel/extra/dkms_test.ko${mod_compression_ext}" \
1869-
"/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
1870-
rmdir --ignore-fail-on-non-empty "/lib/modules/${KERNEL_VER}/kernel/extra" "/lib/modules/${KERNEL_VER}/kernel"
1871-
fi
1858+
Restoring archived original module /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
1859+
Running depmod... done.
1860+
EOF
18721861
run_status_with_expected_output 'dkms_replace_test' << EOF
18731862
dkms_replace_test/2.0: added
18741863
EOF
@@ -1910,19 +1899,11 @@ run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_replace_test -v
19101899
Module dkms_replace_test/2.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}):
19111900
Before uninstall, this module version was ACTIVE on this kernel.
19121901
Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
1913-
Restoring archived original module
1902+
Restoring archived original module /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
19141903
Running depmod... done.
1915-
Removing original module(s) from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH})
19161904
19171905
Deleting module dkms_replace_test/2.0 completely from the DKMS tree.
19181906
EOF
1919-
if [ "${expected_dest_loc}" != "kernel/extra" ]; then
1920-
echo 'Moving the restored module back to its correct location (testing artefact)'
1921-
mkdir -p "/lib/modules/${KERNEL_VER}/${expected_dest_loc}"
1922-
mv "/lib/modules/${KERNEL_VER}/kernel/extra/dkms_test.ko${mod_compression_ext}" \
1923-
"/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
1924-
rmdir --ignore-fail-on-non-empty "/lib/modules/${KERNEL_VER}/kernel/extra" "/lib/modules/${KERNEL_VER}/kernel"
1925-
fi
19261907
run_status_with_expected_output 'dkms_replace_test' << EOF
19271908
EOF
19281909
run_status_with_expected_output 'dkms_test' << EOF

0 commit comments

Comments
 (0)