3

Suppose packages I'm building for myprog1 and myprog2 are to install in /usr/lib/mysystem/myprog1/ and /usr/lib/mysystem/myprog2/

According to some distros' documentation, such in the case of OpenSUSE, both packages must own the shared directory. But how is that accomplished in the .spec files? Is the following correct?

%files
/usr/lib/mysystem

or do I need to do

%files
%dir /usr/lib/mysystem
/usr/lib/mysystem/myprog<1|2>
Display Name
  • 2,323
  • 1
  • 26
  • 45

2 Answers2

2

Usually only one package owns a given directory. On a typical system, there will be a package such as "filesystem" which may own things such as /bin. In the case of the filesystem package on Red Hat and OpenSUSE, that package owns /usr/bin but none of the files within that directory.

You could do that, by making a wrapper-package which owns things that are shared across your applications, and making it a dependency (Requires) of the applications which install into those directories.

To see what actually owns something with rpm, you can use the -qf options, e.g.,

rpm -qf /usr/lib/mysystem/myprog

The command works for directories as well as files.

The documentation for %dir and %files is the place to start when deciding how to make a package own a directory. In Maximum RPM: Taking the Red Hat Package Manager to the Limit, chapter 13 Directives For the %files list, it says:

As we mentioned in the section called The %files List, if a directory is specified in the %files list, the contents of that directory, and the contents of every directory under it, will automatically be included in the package

The way to get around this, is to use the %dir directive. By adding this directive to the line containing the directory, RPM will package only the directory itself, regardless of what files are in the directory at the time the package is created. Here's an example of %dir in action.

%dir /usr/blather

So the latter of the suggested cases follows the documentation. However, as a check on whether the syntax is correct (even if the rpm happens to build) it is good practice to examine the list of pathnames.

Investigating Fedora 21 to find packages for which rpm -qf shows the same directory finds several. For example, initscripts and chkconfig use the %dir directive to do this:

%dir /etc/rc.d
%dir /etc/rc.d/rc[0-9].d
%dir /etc/rc.d/init.d

in initscripts spec-file, and

/etc/rc.d
/etc/rc.d/init.d
/etc/rc[0-6].d
/etc/rc.d/rc[0-6].d

in chkconfig spec-file. However, the initscripts package requires /sbin/chkconfig, which is provided by the chkconfig package. Because of that dependency, chkconfig is the actual owner of the directory.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • 1
    It's not the case that only one package can own it. For example, from https://en.opensuse.org/openSUSE:Specfile_guidelines#Ownership : "In this case, each package must own the /usr/share/Foo/Animal directory." I see a similar example in the Fedora packaging guide. – Display Name May 07 '15 at 00:18
  • Documentation can be misleading. The rpm program can tell you what rpm *does*. If you find two concurrently-installed rpms for which `rpm -ql` lists the same path, then that is something that can be discussed. – Thomas Dickey May 07 '15 at 00:20
  • So you're saying the two sets of documentations for two of the biggest distributions are wrong? They even give separate sets of examples. I gave the one from OpenSUSE; here's Fedora: "Solution: Both the git and bzr packages should own the /etc/bash_completion.d directory" This means to me in .spec file's %files section to list the shared directory with the %dir directive (and then without %dir the subdirectories in it that it owns exclusively). – Display Name May 07 '15 at 06:06
  • 2
    As for what rpm does: it does _not_ delete directories containing files it does not know about, so the directory will only be deleted when both packages are removed (unless one of the packages lists the other one's contents in that directory with %ghost). – Display Name May 07 '15 at 06:13
  • Thomas Dickey writes: "If you find two concurrently-installed rpms for which rpm -ql lists the same path, then that is something that can be discussed". I certainly can - I'm trawling Stack Exchange to learn a bit more about rpm dual ownership. – teapot7 Dec 03 '18 at 04:26
1

That depends, especially if the packages for program1 and program2 are built from one source or form completely different sources.

If they come from one source, you have to differentiate in a more sophisticated way:

%files program1
%dir /usr/lib/mysystem
/usr/lib/mysystem/program1

%files program2
%dir /usr/lib/mysystem
/usr/lib/mysystem/program2

If you build them separately, you can just do

%files programX
/usr/lib/mysystem

if you work with a clean buildroot which nevertheless only contains the files created by your package.

But it doesn't hurt to do

%files programX
%dir /usr/lib/mysystem
/usr/lib/mysystem/programX

as well.

If you have several such packages, you could even create a common package which owns that directory and which as well provides other requirements if you have such. It is then sufficient to require this "parent package", "company package" or how you want to name it.

Then it is enough to do

Requires: mysystemcompanypackage
...
%files
/usr/lib/mysystem/program1
glglgl
  • 89,107
  • 13
  • 149
  • 217