Search code examples
rpmrpmbuild

Replace existing directory and all of its content when rpm package is installed


I have created an rpm package and while installing it I want to replace all the existing directory and its contents with rpm package data

Let's say that I have a directory called config/ which has some config files (a.config, b.config, etc.), now a.config is deprecated and I don't want it anymore. So I created a new rpm package with all the files except a.config, but when I install the package it updates b.config and every other file in the directory but it doesn't delete or remove a.config.

I am using following command to install rpm package

rpm -Uvh --force package.rpm

I want to keep only those files and directory that are included in the package and delete other files and folders


Solution

  • To answer my own question,

    whatever step you want to execute before rpm package installation starts, you need to define in %pre script in rpm spec file.

    So I wrote

    %pre
    rm -f a.config
    

    in my spec file and it removed the config file before rpm package installation started