From Fedora Project Wiki

< PackageMaintainers

Revision as of 18:01, 29 July 2009 by Limb (talk | contribs) (moved PackagingDrafts/DirectorySymlinkReplacement to PackageMaintainers/DirectorySymlinkReplacement: Should be linked to from the Guidelines, not *in* the guidelines.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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<directory>
 ln -s <target> $RPM_BUILD_ROOT<directory>

In %post, do something like the following:

 if [ -d <directory> -a ! -L <directory> ]; then
   mv <directory> <directory>.rpmbak && \
   ln -s <target> <directory> && \
   rm -rf <directory>.rpmbak
 if [ ! -L <directory> ]; then
   ln -s <target> <directory>

Then, in %files:

 %ghost <directory>

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