How to show details of error in Alpine apk

7,679

Solution 1

apk fix

This command lists and fixes the errors.

Solution 2

I have run into the same issues and tried to read the source code in order to find out the way of displaying error details. Unfortunately, I think there is no way by apk CLI.

But...

In src/commit.c#L357-L374, It seems like the numeric errors in the output is stored in variable errors. For example, 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);
    }

In src/commit.c#L326-L342, The errors is increased when broken_files or broken_scripts of ipkg (which refer to installed package) is evaluated to true. So there is a change for us to distinguish that.

    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;

After reading code in src/database.c#L874-L885, it shows there is a database file which stores information of installed packages, and it has an undocumented character field f which indicates the error type that we would like to know.

    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;

Proof of Concept

The package fontconfig and gdk-pixbuf both have a broken script (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
Share:
7,679

Related videos on Youtube

user1337
Author by

user1337

Updated on September 18, 2022

Comments

  • user1337
    user1337 almost 2 years

    I use Alpine Linux 3.9.3 x86_64

    when I issue:

    # apk upgrade
    

    the output is:

    3 errors; 1973 MiB in 519 packages
    

    How can I get the details about those 3 errors? I tried the --verbose flag but result is same.

    These are the workarounds I thought would work:

    apk -sv fix
    

    -s (or --simulate) should simulate the fix without doing it and -v (or --verbose) should show more details but neither is working.

    The result is:

    # 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
    

    But still no details, just a short summary. I wish to know what's wrong and I can't find any logs or something like that.

  • user1337
    user1337 about 5 years
    Well, I'm afraid this is not what I'm asking about. The solution you have provided will do the fix when I'd asked about getting details of those errors.