what does the rpmbuild warning "File listed twice" ACTUALLY MEAN?
Asked Answered
H

5

20

I need to specify common attributes for one of the major directories in the package, and special permission for some of it subdirs. e.g.

%files
%attr(-, myuser, mygroup) /opt/myapp 
%attr(750, myuser, mygroup) /opt/myapp/bin  # no exec permission to other
/etc  # this is the reason I can't use %defattr(-, myuser, mygroup)

I get the "file listed twice" warning on every file under /opt/myapp/bin, naturally. My question is, what does it actually mean? What does rpmbuild do with it? I can't find an answer anywhere. Can I just ignore it? What takes precedence, the first or the last occurrence?

I prefer not to list everything under myapp explicitly to solve this. is there any other way? Thanks

Hacker answered 25/12, 2012 at 12:52 Comment(0)
R
6

It means just that - it's listed twice. ;) I've never had a problem with it, but I don't know which will win.

As a side note, you probably shouldn't list /etc on its own, since you don't want to own that.

Raouf answered 25/12, 2012 at 22:7 Comment(3)
This answer is wrong. If you list /etc, the rpm will "own" all files that are in %{buildroot}/etc, not in /etc. So, listing /etc in the %files section is common practice and there isn't any real drawbackPhatic
If you attempt to install two packages that try to own /etc, RPM will refuse to install the second one, which is why it is to be avoided.Unmeaning
This is true only in the case of %dir /etc. If you simply list /etc the files owned by the package are the ones inside of it but not the dir itselfPhatic
P
14

I am posting here just in case someone has the same issue and finds this old question.

Recently (how recently depends on the distro) the macro %exclude has been added to rpmbuild.

%files
%attr(-, myuser, mygroup) /opt/myapp
%exclude /opt/myapp/bin
%attr(750, myuser, mygroup) /opt/myapp/bin  # no exec permission to other

The advantage here is not as evident as having a set of files or folders to exclude:

%files
%attr(-, myuser, mygroup) /opt/myapp
%exclude /opt/myapp/[bin|data|whatever]
%attr(750, myuser, mygroup) /opt/myapp/bin  # no exec permission to other
%attr(777, myuser, myothergroup) /opt/myapp/data
%attr(640, myuser, myothergroup) /opt/myapp/whatever

Strangely the [a|b] syntax works with %exclude but not with the other directives in %files (eg I can use a regex to exclude but not to include, doh)

Phatic answered 6/1, 2015 at 23:25 Comment(5)
thanks, it worked. So I can do /home/oracle/scripts %exclude /home/oracle/scripts/myconfig.config %config(noreplace) /home/oracle/scripts/myconfig.config without the warning about duplicate fileStreeto
Unfortunately on my CentOS 5.5 adding %exclude does not allow me to re-include files later.Greig
While this does suppress the error, it also results in the package not including the file at all on rpmbuild 4.8.0 - which is not exactly the expected result. :)Proctology
@Proctology you need to explicitly include the files you need after the %exclude statement. I haven't built any rpm package in a while, I gotta try it on rpmbuild 4.8.0Phatic
@Phatic I did include after the exclude, just like in the examples where a directory is included, then a subdir and file inside are excluded then included. It was RHEL6, so could just be an old bug / behavior. I really need to move this process to a RHEL7 system anyway. ;)Proctology
W
10

Change it to this:

%files
%dir %attr(-, myuser, mygroup) /opt/myapp
%attr(750, myuser, mygroup) /opt/myapp/bin

notice the %dir for the directory. That should get rid of the files listed twice warning.

Whitman answered 11/2, 2014 at 14:40 Comment(2)
Note that using %dir will make it an empty directory. So this isn't as useful if you need to include everything in /opt/myapp and custom-configure the permissions on just the bin subdir.Pelting
The link in the comment above no longer works. Use ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html instead.Fahland
R
6

It means just that - it's listed twice. ;) I've never had a problem with it, but I don't know which will win.

As a side note, you probably shouldn't list /etc on its own, since you don't want to own that.

Raouf answered 25/12, 2012 at 22:7 Comment(3)
This answer is wrong. If you list /etc, the rpm will "own" all files that are in %{buildroot}/etc, not in /etc. So, listing /etc in the %files section is common practice and there isn't any real drawbackPhatic
If you attempt to install two packages that try to own /etc, RPM will refuse to install the second one, which is why it is to be avoided.Unmeaning
This is true only in the case of %dir /etc. If you simply list /etc the files owned by the package are the ones inside of it but not the dir itselfPhatic
S
1

One reason for this error could be that you have listed the directory as well as the files in that directory under %files.

Example:

%files
%{_bindir}/%{name}-%{version}/dir
%{_bindir}/%{name}-%{version}/dir/file

In this case either you just list the directory like this:

%files
%{_bindir}/%{name}-%{version}/dir

Or list directory as %dir then list files as well, like this:

%files
%dir %{_bindir}/%{name}-%{version}/dir
%{_bindir}/%{name}-%{version}/dir/file
Stimson answered 23/11, 2022 at 11:17 Comment(0)
B
0

I am using the current version of rpmbuild on RH 8.6 and non of these solutions are working. As posted in the comments, %exclude removing the files and directories while %dir removes all the sub-directories and files under it unless specified. Example where servlet_workspace is the tomcat directory path to a directory tree of 2 files and 5 directories being created for the application.

%files
%attr(-, tomcat, tomcat) %{servlet_workspace}
%attr(0664, tomcat, tomcat) %{servlet_workspace}/logs/%{conf_file}.sample
%attr(0775, tomcat, tomcat) %{servlet_workspace}/stitcherStuff/reboot.sh

Putting %dir removes all the subdirectories under servlet_workspace.

%files
%dir %{servlet_workspace}
%attr(0664, tomcat, tomcat) %{servlet_workspace}/logs/%{conf_file}.sample
%attr(0775, tomcat, tomcat) %{servlet_workspace}/stitcherStuff/reboot.sh
Backdrop answered 30/1, 2023 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.