PackageMaintainers/DirectorySymlinkReplacement

From FedoraProject

Jump to: navigation, search

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
 fi 
 if [ ! -L <directory> ]; then
   ln -s <target> <directory>
 fi

Then, in %files:

 %ghost <directory>


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