سؤال

Is it permissible to use %defattr multiple times in spec file? Under Ubuntu 10 (rpm version 4.7.1), the following definition would result in 777 permissions applied to /var/log/testdir2.

%files
%defattr(-,root,root,-)
%dir /var/log/testdir1
%defattr(777,root,root,-)
%dir /var/log/testdir2
%dir %attr(777,root,root) /var/log/testdir3

After upgrading to Ubuntu 12.04.1 (x86_64RPM version 4.9.1.1), regenerating the rpm with the same spec file and deploying to the same target machine resulted in /var/log/testdir2 having permissions 755. I have to change the spec file to define %attr as in /var/log/testdir3 above in order to get the desired permissions.

The spec file had a %defattr definition followed by the set of files having those permissions, then another %defattr definition followed by the set of files with those permissions. Is that not allowed? Or is there a difference between how directories and files are treated with regard to permissions?

هل كانت مفيدة؟

المحلول

%defattr is usually used to set the default attributes for files/directories, so using it multiple times seems odd to me. First let's look at the %defattr values: %defattr(file perms, user, group, dir perms). So probably the /var/log/testdir3 directory has permissions of 755 in your tarball since you're not setting the directory permissions, it's just inheriting them.

Try something like this:

%files
%defattr(755,root,root,777)
%dir /var/log/testdir1
%dir /var/log/testdir2
%dir /var/log/testdir3

Using what I have above, it will set the directories to 777, and then set all files that you list to 755 because it's inheriting the default values (both with ownership of root.root).

I'm still a bit confused as to why you're setting permissions on a log dir to 777, as when you declare the %dir it only sets the directory permissions. Are you not trying to set the files to something? If you need a specific directory with different permissions you should be using the %attr attribute.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top