mirror of https://github.com/armbian/build.git
`apt_purge_unneeded_packages_and_clean_apt_caches()`: count files, don't use `du`: avoid WARNs when not needed; tolerate 1 file
- 'lock' might or not be there, tolerate 1 file (not 0)
This commit is contained in:
parent
99e065381a
commit
25929ea6ac
|
|
@ -172,7 +172,7 @@ function local_apt_deb_cache_prepare() {
|
|||
if ! mountpoint -q "${sdcard_var_cache_apt_dir}"; then
|
||||
declare -i sdcard_var_cache_apt_files_count
|
||||
sdcard_var_cache_apt_files_count=$(find "${sdcard_var_cache_apt_dir}" -type f | wc -l)
|
||||
if [[ "${sdcard_var_cache_apt_files_count}" -gt 0 ]]; then
|
||||
if [[ "${sdcard_var_cache_apt_files_count}" -gt 1 ]]; then # 1 cos of lockfile that might or not be there
|
||||
display_alert "WARNING: SDCARD /var/cache/apt dir is not empty" "${when_used} :: ${sdcard_var_cache_apt_dir} (${sdcard_var_cache_apt_files_count} files)" "wrn"
|
||||
run_host_command_logged ls -lahtR "${sdcard_var_cache_apt_dir}" # list the contents so we can try and identify what is polluting it
|
||||
fi
|
||||
|
|
@ -185,7 +185,7 @@ function local_apt_deb_cache_prepare() {
|
|||
if ! mountpoint -q "${sdcard_var_lib_apt_lists_dir}"; then
|
||||
declare -i sdcard_var_lib_apt_lists_files_count
|
||||
sdcard_var_lib_apt_lists_files_count=$(find "${sdcard_var_lib_apt_lists_dir}" -type f | wc -l)
|
||||
if [[ "${sdcard_var_lib_apt_lists_files_count}" -gt 0 ]]; then
|
||||
if [[ "${sdcard_var_lib_apt_lists_files_count}" -gt 1 ]]; then # 1 cos of lockfile that might or not be there
|
||||
display_alert "WARNING: SDCARD /var/lib/apt/lists dir is not empty" "${when_used} :: ${sdcard_var_lib_apt_lists_dir} (${sdcard_var_lib_apt_lists_files_count} files)" "wrn"
|
||||
run_host_command_logged ls -lahtR "${sdcard_var_lib_apt_lists_dir}" # list the contents so we can try and identify what is polluting it
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -14,35 +14,30 @@ function apt_purge_unneeded_packages_and_clean_apt_caches() {
|
|||
|
||||
declare dir_var_lib_apt_lists="/var/lib/apt/lists"
|
||||
declare dir_var_cache_apt="/var/cache/apt"
|
||||
declare -i dir_var_cache_apt_size_mb dir_var_cache_apt_size_after_cleaning_mb dir_var_lib_apt_lists_size_mb
|
||||
declare -i dir_var_cache_apt_file_count dir_var_lib_apt_lists_file_count
|
||||
|
||||
# Now, let's list what is under ${SDCARD}/var/cache/apt -- it should be empty. If it isn't, warn, and clean it up.
|
||||
dir_var_cache_apt_size_mb="$(du -sm "${SDCARD}${dir_var_cache_apt}" | cut -f1)"
|
||||
if [[ "${dir_var_cache_apt_size_mb}" -gt 0 ]]; then
|
||||
display_alert "SDCARD ${dir_var_cache_apt} is not empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_size_mb}MB" "wrn"
|
||||
# list the contents
|
||||
dir_var_cache_apt_file_count="$(find "${SDCARD}${dir_var_cache_apt}" -type f | wc -l)"
|
||||
if [[ "${dir_var_cache_apt_file_count}" -gt 1 ]]; then # there is sometimes at least one file, the lock file
|
||||
display_alert "SDCARD ${dir_var_cache_apt} is not empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_file_count} files" "wrn"
|
||||
run_host_command_logged ls -lahtR "${SDCARD}${dir_var_cache_apt}"
|
||||
wait_for_disk_sync "after listing ${SDCARD}${dir_var_cache_apt}"
|
||||
else
|
||||
display_alert "SDCARD ${dir_var_cache_apt} is empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_size_mb}MB" "debug"
|
||||
display_alert "SDCARD ${dir_var_cache_apt} is empty" "${dir_var_cache_apt} :: ${dir_var_cache_apt_file_count} files" "debug"
|
||||
fi
|
||||
|
||||
# attention: this is _very different_ from `chroot_sdcard_apt_get clean` (which would clean the cache)
|
||||
chroot_sdcard apt-get clean
|
||||
wait_for_disk_sync "after apt-get clean"
|
||||
|
||||
dir_var_cache_apt_size_after_cleaning_mb="$(du -sm "${SDCARD}${dir_var_cache_apt}" | cut -f1)"
|
||||
display_alert "SDCARD ${dir_var_cache_apt} size after cleaning" "${dir_var_cache_apt} :: ${dir_var_cache_apt_size_after_cleaning_mb}MB" "debug"
|
||||
|
||||
# Also clean ${SDCARD}/var/lib/apt/lists; this is where the package lists are stored.
|
||||
dir_var_lib_apt_lists_size_mb="$(du -sm "${SDCARD}${dir_var_lib_apt_lists}" | cut -f1)"
|
||||
if [[ "${dir_var_lib_apt_lists_size_mb}" -gt 0 ]]; then
|
||||
display_alert "SDCARD ${dir_var_lib_apt_lists} is not empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_size_mb}MB" "wrn"
|
||||
# list the contents
|
||||
dir_var_lib_apt_lists_file_count="$(find "${SDCARD}${dir_var_lib_apt_lists}" -type f | wc -l)"
|
||||
if [[ "${dir_var_lib_apt_lists_file_count}" -gt 1 ]]; then # there is sometimes at least one file, the lock file
|
||||
display_alert "SDCARD ${dir_var_lib_apt_lists} is not empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_file_count} files" "wrn"
|
||||
run_host_command_logged ls -lahtR "${SDCARD}${dir_var_lib_apt_lists}"
|
||||
wait_for_disk_sync "after listing ${SDCARD}${dir_var_cache_apt}"
|
||||
else
|
||||
display_alert "SDCARD ${dir_var_lib_apt_lists} is empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_size_mb}MB" "debug"
|
||||
display_alert "SDCARD ${dir_var_lib_apt_lists} is empty" "${dir_var_lib_apt_lists} :: ${dir_var_lib_apt_lists_file_count} files" "debug"
|
||||
fi
|
||||
|
||||
# Either way, clean it away, we don't wanna ship those lists on images or rootfs.
|
||||
|
|
|
|||
Loading…
Reference in New Issue