![如何在 Alpine apk 中显示错误详细信息](https://linux22.com/image/152934/%E5%A6%82%E4%BD%95%E5%9C%A8%20Alpine%20apk%20%E4%B8%AD%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF.png)
我使用 Alpine Linux 3.9.3 x86_64
当我发出:
# apk upgrade
输出是:
3 errors; 1973 MiB in 519 packages
我如何才能获取这 3 个错误的详细信息?我尝试了该--verbose
标志,但结果是相同的。
这些是我认为可行的解决方法:
apk -sv fix
-s
(或--simulate
) 应该模拟修复而不执行此操作,并且-v
(或--verbose
) 应该显示更多详细信息,但两者都不起作用。
结果是:
# apk -sv fix
(1/3) Reinstalling fuse-common (3.2.6-r1)
(2/3) Reinstalling fuse-openrc (3.2.6-r1)
(3/3) Reinstalling xorgproto (2018.4-r0)
3 errors; 524 packages, 2845 dirs, 48016 files, 2002 MiB
但仍然没有细节,只是一个简短的总结。我想知道出了什么问题,但我找不到任何日志或类似的东西。
答案1
apk fix
此命令列出并修复错误。
答案2
我遇到了同样的问题并尝试阅读源代码以找出显示错误详细信息的方式。不幸的是,我认为 CLI 没有办法apk
。
但...
在src/commit.c#L365-L382,看起来输出中的数字错误存储在变量中errors
。例如,3 errors; 1973 MiB in 519 packages
。
if (errors)
snprintf(buf, sizeof(buf), "%d error%s;", errors,
errors > 1 ? "s" : "");
else
strcpy(buf, "OK:");
if (apk_verbosity > 1) {
apk_message("%s %d packages, %d dirs, %d files, %zu MiB",
buf,
db->installed.stats.packages,
db->installed.stats.dirs,
db->installed.stats.files,
db->installed.stats.bytes / (1024 * 1024));
} else {
apk_message("%s %zu MiB in %d packages",
buf,
db->installed.stats.bytes / (1024 * 1024),
db->installed.stats.packages);
}
在src/commit.c#L333-L352,当ipkg(指已安装的软件包)的或评估为 true 时,该errors
值会增加。所以我们有机会区分这一点。broken_files
broken_scripts
r = change->old_pkg &&
(change->old_pkg->ipkg->broken_files ||
change->old_pkg->ipkg->broken_script);
if (print_change(db, change, prog.done.changes, prog.total.changes)) {
prog.pkg = change->new_pkg;
progress_cb(&prog, 0);
if (!(apk_flags & APK_SIMULATE) &&
((change->old_pkg != change->new_pkg) ||
(change->reinstall && pkg_available(db, change->new_pkg)))) {
r = apk_db_install_pkg(db, change->old_pkg, change->new_pkg,
progress_cb, &prog) != 0;
}
if (r == 0 && change->new_pkg && change->new_pkg->ipkg)
change->new_pkg->ipkg->repository_tag = change->new_repository_tag;
}
errors += r;
阅读完代码后src/database.c#L874-L885,它显示有一个数据库文件,存储已安装软件包的信息,并且它有一个无证的字符字段f
指示我们想知道的错误类型。
case 'f':
for (r = 0; r < l.len; r++) {
switch (l.ptr[r]) {
case 'f': ipkg->broken_files = 1; break;
case 's': ipkg->broken_script = 1; break;
case 'x': ipkg->broken_xattr = 1; break;
default:
if (!(apk_force & APK_FORCE_OLD_APK))
goto old_apk_tools;
}
}
break;
概念验证
该软件包fontconfig
和gdk-pixbuf
两者都有损坏的脚本 ( f:s
)。
$ docker run -it --rm richarvey/nginx-php-fpm:1.5.7 sh
# apk --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/main add jq sqlite imagemagick gearmand@testing
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
(1/53) Installing boost-program_options (1.71.0-r0)
(2/53) Installing libcrypto1.1 (1.1.1d-r2)
(3/53) Installing libssl1.1 (1.1.1d-r2)
(4/53) Installing libevent (2.1.10-r0)
(5/53) Installing libuuid (2.34-r0)
(6/53) Installing gearman-libs@testing (1.1.18-r7)
(7/53) Installing hiredis (0.14.0-r2)
(8/53) Installing libmemcached-libs (1.0.18-r4)
(9/53) Installing gearmand@testing (1.1.18-r7)
Executing gearmand-1.1.18-r7.pre-install
(10/53) Installing libxau (1.0.9-r0)
(11/53) Installing libbsd (0.10.0-r0)
(12/53) Installing libxdmcp (1.1.3-r0)
(13/53) Installing libxcb (1.13.1-r0)
(12/53) Installing libxdmcp (1.1.3-r0)
(13/53) Installing libxcb (1.13.1-r0)
(14/53) Installing libx11 (1.6.9-r0)
(15/53) Installing libxext (1.3.4-r0)
(16/53) Installing fontconfig (2.13.1-r2)
(17/53) Installing lcms2 (2.9-r1)
(18/53) Installing libltdl (2.4.6-r6)
(19/53) Installing imagemagick-libs (7.0.8.64-r0)
(20/53) Installing libxrender (0.9.10-r3)
(21/53) Installing pixman (0.38.4-r0)
(22/53) Installing cairo (1.16.0-r2)
(23/53) Installing libblkid (2.34-r0)
(24/53) Installing libmount (2.34-r0)
(25/53) Installing glib (2.62.1-r0)
(26/53) Installing dbus-libs (1.12.16-r1)
(27/53) Installing avahi-libs (0.7-r2)
(28/53) Installing gmp (6.1.2-r1)
(29/53) Installing nettle (3.5.1-r0)
(30/53) Installing p11-kit (0.23.18.1-r0)
(31/53) Installing libtasn1 (4.14-r0)
(32/53) Installing libunistring (0.9.10-r0)
(33/53) Installing gnutls (3.6.10-r0)
(34/53) Installing cups-libs (2.2.12-r0)
(35/53) Installing jbig2dec (0.16-r0)
(36/53) Installing tiff (4.0.10-r1)
(37/53) Installing ghostscript (9.27-r4)
(38/53) Installing libde265 (1.0.3-r0)
(39/53) Installing x265-libs (3.2-r0)
(40/53) Installing libheif (1.5.1-r1)
(41/53) Installing libxft (2.3.3-r0)
(42/53) Installing fribidi (1.0.7-r0)
(43/53) Installing graphite2 (1.3.13-r1)
(44/53) Installing harfbuzz (2.6.2-r0)
(45/53) Installing pango (1.44.6-r0)
(46/53) Installing libcroco (0.6.13-r1)
(47/53) Installing shared-mime-info (1.12-r1)
(48/53) Installing gdk-pixbuf (2.40.0-r0)
(49/53) Installing librsvg (2.40.20-r0)
(50/53) Installing imagemagick (7.0.8.64-r0)
(51/53) Installing oniguruma (6.9.3-r0)
(52/53) Installing jq (1.6-r0)
(53/53) Installing sqlite (3.25.3-r2)
Executing busybox-1.28.4-r1.trigger
Executing ca-certificates-20171114-r3.trigger
Executing fontconfig-2.13.1-r2.trigger
Error relocating /lib/libuuid.so.1: getrandom: symbol not found
ERROR: fontconfig-2.13.1-r2.trigger: script exited with error 127
Executing shared-mime-info-1.12-r1.trigger
Executing gdk-pixbuf-2.40.0-r0.trigger
Error relocating /lib/libmount.so.1: getrandom: symbol not found
Error relocating /lib/libblkid.so.1: getrandom: symbol not found
ERROR: gdk-pixbuf-2.40.0-r0.trigger: script exited with error 127
OK: 293 MiB in 136 packages
# apk fix -sv
(1/2) [APK unavailable, skipped] Reinstalling fontconfig (2.13.1-r2)
(2/2) [APK unavailable, skipped] Reinstalling gdk-pixbuf (2.40.0-r0)
2 errors; 155 packages, 1117 dirs, 15483 files, 456 MiB
# cat /lib/apk/db/installed | grep '^f:' -C 20 | grep '^\(P\|f\):'
P:fontconfig
f:s
P:gdk-pixbuf
f:s