Reinstalling all packages broke some of them ?!

I created a script to reinstall all packages for maintenance purposes in case some of them get broken over time (I had done something similar for arch in the past).

sudo dnf reinstall --refresh $(rpm -qa --qf "%{NAME}\n")

After successful finish, running java shows “command not found” and which java doesn’t find the binary. Also update-alternatives --list doesn’t show java at all. Doing sudo dnf reinstall java-openjdk java-openjdk-devel doesn’t fix the problem. However, doing sudo dnf remove java-openjdk java-openjdk-devel and then sudo dnf install java-openjdk java-openjdk-devel fixes the problem.

How did this happen with just reinstalling all packages? I have over 6500 packages installed, so how can I know which of them are broken and find a way to fix them?

That was an interesting observation!

The installation scripts of the Java package handles the registration of Java in the alternatives system. When a package is installed, the binaries installed are registered in alternatives, when it is uninstalled the same binaries are removed from alternatives. When both things happen in the same transaction, typically during an upgrade, these scripts are run in a specific order.

During an upgrade, this works just fine. The old binaries are unregistered, the new ones are registered.

During reinstallation however, it is the same version that is registered and unregistered. And since post-uninstallation scripts are run after post-installation scripts (see the link above), the latter ones “win”. Ergo, the binaries are not registered after the transaction.

You could argue this is a bug in the Java packaging. The package scripts don’t handle the reinstallation case properly. You could file a case about it if you like and see what the packager might think. I’m not sure there is any easy solution.

(Personally, I consider reinstallations something quite unusual. Packages should not “get broken over time”. If a package break I would try to investigate why it happened to avoid it in the future. But I guess YMMV, and I have occasionally reinstalled some package.)

1 Like

Thx for detailed explanation, I think I found the reported bug which is this one

I am fairly new to Fedora (I had used it in the past but only to test it, but only recently I switched to fedora as my main distro). I’ve learned packaging for both arch and Solus and the most annoying thing about Fedora’s packaging is the excessive usage of scriptlets. Shouldn’t the alternatives configuration be part of the package files instead of been registered and unregistered with scriptlets, as a general rule for all packages. If I’ve understood correctly how alternatives work, the installation of an alternative is pretty much a link to the specific installation location. Couldn’t this just be created cleanly during the %install section and be just part of the package files instead of using scriptlets? Maybe I can raise this as a bug/discussion somewhere more general, than just the openjdk packages?

1 Like

Right, well spotted. It seems you were not the first one to hit the issue.