From Fedora Project Wiki
m (formatting/typos)
Line 9: Line 9:
=== Working around it with scriptlets ===   
=== Working around it with scriptlets ===   


To work around this problem, you must include a [[Packaging:Guidelines#The_.25pretrans_scriptlet|%pretrans scriptlet written in lua]] that manually performs the conversion prior to RPM attempting to install the package. Please use whichever of the two following snippets is necessary in packages that need this transition, replacing <code>&lt;path to dir&gt;</code> with the path to the directory that is being converted.
To work around this problem, you must include a [[Packaging:Guidelines#The_.25pretrans_scriptlet|%pretrans scriptlet]] that manually performs the conversion prior to RPM attempting to install the package.
 
%pretrans scriptlets must use -p <lua> to survive initial system installation, but since there will never be transitions like these to perform on initial system installation, we can count on a shell being present when we actually perform the conversion. This means that we need to use -p <lua> in order to test if the replacement needs to be made, but we can safely shell out using os.execute() to actually perform the replacement.
 
Please use whichever of the two following snippets is necessary in packages that need this transition, replacing <code>&lt;path to dir&gt;</code> with the path to the directory that is being converted.


==== Scriptlet to replace a directory with a symlink ====
==== Scriptlet to replace a directory with a symlink ====

Revision as of 03:12, 22 February 2014

Replacing a directory with a symlink or vice versa

Due to a known limitation with RPM, it is not possible to replace a directory with a symlink, nor is it possible to replace a symlink with a directory, without RPM producing file conflict errors while trying to install the package. For more information on the issues involved, refer to bug 447156 and bug 646523.

Try to avoid the problem in the first place

While its obviously not possible to foresee all the cases where the need might arise, when the need is foreseeable, such as with bundled libraries, it'd be better to use a symlink from the start, as the symlink target can be changed more easily. For instance, if you have a bundled libfoo library inside the packages directory structure, place it in a eg. libfoo.bundled directory and make libfoo a symlink to that. When the bundling is eventually removed, you just need to drop the directory and change the symlink to point to the corresponding system library directory, without resorting to the scriptlets described below.

Working around it with scriptlets

To work around this problem, you must include a %pretrans scriptlet that manually performs the conversion prior to RPM attempting to install the package.

%pretrans scriptlets must use -p <lua> to survive initial system installation, but since there will never be transitions like these to perform on initial system installation, we can count on a shell being present when we actually perform the conversion. This means that we need to use -p <lua> in order to test if the replacement needs to be made, but we can safely shell out using os.execute() to actually perform the replacement.

Please use whichever of the two following snippets is necessary in packages that need this transition, replacing <path to dir> with the path to the directory that is being converted.

Scriptlet to replace a directory with a symlink

%pretrans -p <lua>
st = posix.stat("<path to dir>")
if st and st.type == "directory" then
  os.execute("rm -rf <path to dir>")
end

Scriptlet to replace a symlink with a directory

%pretrans -p <lua>
st=posix.stat("<path to dir>")
if st and st.type == "link" then
  os.remove("<path to dir>")
  posix.mkdir("<path to dir>")
end