FAQ:Change Permissions on Installed Directories and Files
From rPath Wiki
| FAQ | ||
| Question: How do I use my Conary recipe to change permissions on directory or file after it is installed? | ||
|
Answer: Permissions and ownership are handled by build and policy actions in the Conary package recipe classes. You can change permissions and ownership on existing directories and files, and you can create directories with particular permissions and ownership. See the following sections for information and examples.
Change Permissions
To change permissions on a file or directory, use the r.SetModes build action in the package recipe as listed in the Conary:Package Recipe Classes. This applies to file or directories in the directories that can be identified by the %(destdir)s and %(builddir)s macros. The arguments are one or more files or directories followed by the digits used to set permissions with the chmod Linux command. In the following example, the line is used to make a file writable by the owner and readable by everyone:
r.SetModes('%(destdir)s/Settings.php', 0644)
Change Ownership
To change ownership on a file or directory installed by a Conary package, use the r.Ownership policy action in the package recipe as listed in the Conary:Package Recipe Classes. The first two arguments passed are equivalent to the user and group arguments used in the chown Linux command. Note that Conary will set the ownership to root:root unless otherwise specified. The line in the recipe's setup(r) method should resemble the following:
r.Ownership('apache', 'apache', '%(localstatedir)s/lib/php/session')
Note that Conary must have info packages for the username and group. See Conary:Info Recipe for more information.
Create Directories
By default, Conary does not allow empty directories as part of installing software. To create a new directory in spite of this Conary policy, use the r.MakeDirs build action with the r.ExcludeDirectories policy action. Permissions on the new directory are set in the last argument of MakeDirs using the digits used to set permissions with the chmod Linux command. In the following example lines, a new directory is created, it is set as an exception to Conary's default policy, and the ownership is set on that directory.
r.MakeDirs('%(destdir)s/Themes', 0755) r.ExcludeDirectories(exceptions = '%(destdir)s/Themes') r.Ownership('apache', 'root', '%(destdir)s/Themes')
Note that policy actions like ExcludeDirectories and Ownership take regular expressions as input while build actions like MakeDirs and SetModes take shell-style file globs. For example, r.MakeDirs() would take /foo/{bar,baz}/, and r.ExcludeDirectories() and r.Ownership() would take /foo/(bar|baz)/..
