Making midnight commander understand old and new RPM formats

If you are an avid fan of midnight commander (like me) and you happen to inspect RPM files from time to time (like me too), you may have been irritated by a change in the RPM format.

In the past the payload of the RPM package was a simple cpio file. You could use the rpm2cpio tool to extract the cpio payload from the RPM or simply open it using midnight commander.

Nowadays the payload is not a mere cpio archive, but an LZMA compressed cpio archive. And as a result you cannot open Fedora 13 or RHEL6 RPM packages on older RPM versions with the commands you are used to. Same problem with midnight commander (which bails out in an ugly way).

A few weeks ago I looked into the problem and fixed it on my RHEL5 system, the solution is quite simple, look at the RPMVERSION tag in the package, if it's newer than 4.7 process the rpm2cpio output with xz. What's more, I also implemented two types of payloads so it's visible from the directory listing whether it is a .cpio or a .cpio.xz. The patch looks like this: