Skip to content

Commit 07fe58b

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

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

dkms.in

+23
Original file line numberDiff line numberDiff line change
@@ -1888,9 +1888,32 @@ 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+
for origin_file in $(find "$original_module_backup_dir" -type f -name "$m.*.origin")
1894+
do
1895+
local original_module
1896+
original_module=${origin_file%.origin}
1897+
[[ -f $original_module ]] || continue
1898+
local original_location
1899+
original_location=$(cat "$origin_file")
1900+
case $original_location in
1901+
"$install_tree/$1/"*)
1902+
echo "Restoring archived original module $original_location"
1903+
mkdir -p "${original_location%/*}"
1904+
mv -f "$original_module" "$original_location"
1905+
rm -f "$origin_file"
1906+
;;
1907+
*) warn "Bad original location '$origin' in $origin_file"
1908+
;;
1909+
esac
1910+
done
1911+
find "$original_module_backup_dir" -type d -empty -delete
1912+
fi
18911913
local origmod
18921914
origmod=$(compressed_or_uncompressed "$original_module_backup_dir" "$m")
18931915
if [[ -n $origmod ]]; then
1916+
# Module was archived by older dkms versions without creating .origin
18941917
echo "Restoring archived original module"
18951918
mkdir -p "$install_tree/$1${DEST_MODULE_LOCATION[$count]}/"
18961919
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)