ctron / rpm-builder

Maven RPM builder plugin
https://ctron.github.io/rpm-builder
Eclipse Public License 2.0
55 stars 32 forks source link

Wrong order of entries can produce uninstallable RPMs #14

Open oreinert opened 7 years ago

oreinert commented 7 years ago

Consider the example in the following archive: pluginbug.zip

It contains sources for building a simple RPM containing:

There's a pom.xml file for building the RPM via the Maven RPM plugin, and a .spec file for building the same RPM using the rpmbuild command (by running rpmbuild --define="%_topdir $PWD" -bb SPECS/rpm-plugin-test.spec).

In the example, %dir /opt/test is specified after the file, and this causes the Maven plugin to generate an RPM that can't be installed:

$ sudo rpm -i target/rpm-plugin-test-0.1.0-1-noarch.rpm
error: unpacking of archive failed on file /opt/test/README.md;59198b61: cpio: open failed - No such file or directory
error: rpm-plugin-test-0.1.0-1.noarch: install failed

The same RPM generated using rpmbuild installs without issue. Looking at the entries in the cpio archive within the two RPMs seems revealing:

$ rpm2cpio target/rpm-plugin-test-0.1.0-1-noarch.rpm | cpio -tv
-rw-r--r--   1 root     root           48 May 15 12:51 ./opt/test/README.md
drwxr-xr-x   2 root     root            0 May 15 12:51 ./opt/test
1 block
$ rpm2cpio RPMS/noarch/rpm-plugin-test-0.1.0-0.noarch.rpm | cpio -tv
drwxr-xr-x   2 root     root            0 May 15 12:51 ./opt/test
-rw-r--r--   1 root     root           48 May 15 12:51 ./opt/test/README.md
1 block

The problem seems to be that the RPM generated by the plugin fails to install because cpio can't write the README.md file because the folder it should be in doesn't exist yet. The Maven plugin should order entries in the archive in such a way that it can always be installed, like the rpmbuild command.

Fixing the given example is trivial, of course - just swap the order of the entries. However, for more complicated builds, this may not be possible, especially when profiles are used to contribute independent parts of the RPM plugin config using stuff like http://blog.sonatype.com/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/ .

ctron commented 7 years ago

Yes it is true, this condition is not being checked. And I agree, although there is a workaround for that, there should be some proper solution.