How to set owner for directory in the %files?

Eran Ben-Natan picture Eran Ben-Natan · Apr 1, 2012 · Viewed 21.4k times · Source

If I have this line in the %files:

%attr(0555, myuser, myuser) /opt/myapp/lib/my.jar

Then my.jar will have myuser as owner, but directory /opt/myapp/lib will be owner by root. I don't want to write

%attr(0555, myuser, myuser) /opt/myapp/lib/

as I don't want all files in /opt/myapp/lib/ to be included.

How can I set owner for /opt/myapp/lib/ directory?

Thanks.

Answer

Javaguru picture Javaguru · Apr 3, 2012

I'm not an RPM expert.. but as far as I know, you could use the %dir directive as follows:

%files
%dir %attr(0555, myuser, myuser) /opt/myapp/lib
%attr(0555, myuser, myuser) /opt/myapp/lib/my.jar

or, even simpler:

%files
%defattr(555,myuser,myuser,555)
%dir /opt/myapp/lib
/opt/myapp/lib/my.jar

The %dir directive allows you to add the directory, but not its content.