PackageMaintainers/DirectorySymlinkReplacement

Replacing a Directory with a Symlink
There are many reasons you might need to replace a directory with a symlink. The most common is the migration of a package from the use of a bundled library to a system library. This is commonly needed in PHP applications, but might be applied to any type of package.

Simply removing the offending directory in %install and creating the symlink is not sufficient. This will result in a cpio rename/archive unpack error at upgrade.

A method that I've found to work, with Rex Dieter's help, is the following:

In %install, remove the offending directory, then create the symlink to the target directory:

rm $RPM_BUILD_ROOT ln -s $RPM_BUILD_ROOT

In %post, do something like the following:

if [ -d -a ! -L ]; then mv .rpmbak && \ ln -s && \ rm -rf .rpmbak fi  if [ ! -L ]; then ln -s fi

Then, in %files:

%ghost

This should be sufficient to allow the upgrade to be carried out correctly.